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; |