How to order the attributes in an DOM Element?
Hi,
I have written a java program to create an XML using DOM.
Now I want to add elements to the XML document with some attributes. But the order of the attributes in XML file is not the same as I added. So How can I set the order for the attributes.
Is there any API available?? Kindly help.
My Code is like this:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.newDocument();
Element rootTag = doc.createElement("Root");
doc.appendChild(rootTag);
Element childTag = doc.createElement("Child");
childTag.setAttribute("name","value1");
childTag.setAttribute("description","value2");
rootTag.appendChild(childTag);
The expected Output:
<Root>
<Child name="value1" description="value2"/>
</Root>
The Actual Result:
<Root>
<Child description="value2" name="value1"/>
</Root>
Regards,
Purush