Element rootList, firstList, secondItem, thirdItem; //根元素标签名 rootList = new Element("root"); //根元素标签内的属性名与值 rootList.setAttribute("project", pname); //生成Doc文档 Document Doc = new Document(rootList); //获取文档中的根标签 rootList = Doc.getRootElement(); for (int i = 0; i < judges.size(); i++) { //生成新的元素 firstList = new Element("flayout"); firstList.setAttribute("percent", "percent"); //加入根级元素中 rootList.addContent(firstList); } XMLOutputter XMLOut = new XMLOutputter(); //将doc文档转换为字符串型的XML格式 String xmlinfo = XMLOut.outputString(Doc); //将开头的去掉 xmlinfo = xmlinfo.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); //返回已经封装好的XML数据 return xmlinfo; |