I am trying to create multiple element with the same name using JDOM, the XML file should be output as following:
<data>
<series name="Related">
<point name="aaaa" y="1" />
<point name="bbbb" y="0" />
<point name="cccc" y="2" />
<point name="dddd" y="3" />
</series>
<series name="Not-Related" >
<point name="CE901" y="1" />
<point name="aaa" y="1" />
<point name="bbb" y="1" />
<point name="rrr" y="1" />
<point name="rrr" y="1" />
</series>
</data>
And I tried to code it as:
for (int i = 0; i < 2; i++) {
doc1.getRootElement().getChild("charts").getChild("chart").getChild("data").addContent(new Element("series").setAttribute("name", "Related"));
for (int j = 0; j < 4; j++) {
doc1.getRootElement().getChild("charts").getChild("chart").getChild("data").getChild("series").addContent(new Element("point").setAttribute("name", "CE901").setAttribute("y","1"));
}
}
However the above code output the following XML, which is wrong:
<data>
<series name="Related">
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
<point name="CE901" y="1"/>
</series>
<series name="Related"/>
Can you please help me to find such way precisely to write more than one elements with the same names using JDOM?
Thank you..