This is how I want my XML file to look:

<root>
<data>
<track src="123456">
<desc id="1" mt="audio/mp3" ra="24" dr="221" nv="10005761">Madonna - La Isla Bonita</desc>
<clipdata>PD94bWwgdmVyc2lvbj0iMS4wIiBlb</clipdata>
</track>
</data>
<completed/>
</root>

And this some part of my code:

AttributesImpl atts = new AttributesImpl();
		AttributesImpl atts2 = new AttributesImpl();
		AttributesImpl attsEmpty = new AttributesImpl();

		try {
			this.xml.startElement("", "", "root", atts);
			this.xml.startElement("", "", "data", atts);
			atts.clear();

			atts.addAttribute("", "", "src", "cdata", "123456");
			this.xml.startElement("", "", "track", atts);

			atts2.addAttribute("", "", "id", "cdata", "1");
			atts2.addAttribute("", "", "mt", "cdata", "audio/mp3");
			atts2.addAttribute("", "", "ra", "cdata", "24");
			atts2.addAttribute("", "", "dr", "cdata", "221");
			atts2.addAttribute("", "", "nv", "cdata", "10005761");
			addCharacters(atts2, "desc", "Madonna - La Isla Bonita");
			this.xml.startElement("", "", "desc", atts2);
			this.xml.endElement("", "", "desc");

			addCharacters(attsEmpty, "clipdata", "PD94bWwgdmVyc2lvbj0iMS4wIiBlb");

			this.xml.endElement("", "", "track");

			this.xml.endElement("", "", "data");

			addCompleted();

			this.xml.endElement("", "", "root");

But my resulting XML file looks like this:

<root>
<data>
<track src="123456">
<desc id="1" mt="audio/mp3" ra="24" dr="221" nv="10005761">Madonna - La Isla Bonita</desc>
<desc id="1" mt="audio/mp3" ra="24" dr="221" nv="10005761"/>
<clipdata>PD94bWwgdmVyc2lvbj0iMS4wIiBlb</clipdata>
</track>
</data>
<completed/>
</root>

What should I need to change to not get the second <desc id="1" mt="audio/mp3" ra="24" dr="221" nv="10005761"/> ? I'm sure its a problem of ordering the tag elements, but I just can't get it right.

Someone has an idee ?
Thanks.

PS: addCompleted() -> add's a completed tag at the end.
addCharacters() -> add's a string between tag elements: <tag>string</tag>

Just guessing here, but I think your problem is in

addCharacters(atts2, "desc", "Madonna - La Isla Bonita");
this.xml.startElement("", "", "desc", atts2);
this.xml.endElement("", "", "desc");

for once addCharacters has no returns so it behaves inconsistently (we need to see code for it), secondly we have no idea what startElement and endElement do (need to see code). I would suggest to use some more easier-newer XML library something like XStream

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.