问题描述
节点类似于:请帮忙看下!!!!我试过一些,在网上也找过找不到答案。。。<?xml version="1.0" encoding="UTF-8"?><report type="0"> <chart id="chartId"> <data-collection id="collectionId1"> <data>2011-3-22,3.5</data> <data>2011-3-22,2.0</data> </data-collection> <data-collection id="collectionId2"> <data>2011-3-22,3.5</data> <data>2011-3-22,2.0</data> </data-collection> </chart></report>
解决方案
Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("report").addAttribute("type", "0"); Element chart = root.addElement("chart").addAttribute("id", "chartId"); Element data_collection1 = chart.addElement("data_collection").addAttribute("id", "collectionId1"); data_collection1.addElement("data").addText("2011-3-22,3.5"); data_collection1.addElement("data").addText("2011-3-22,2.0"); Element data_collection2 = chart.addElement("data_collection").addAttribute("id", "collectionId2"); data_collection2.addElement("data").addText("2011-3-22,3.5"); data_collection2.addElement("data").addText("2011-3-22,2.0"); System.out.println(doc.asXML());