javax.xml.transform.Transformer swaps elements attributes after transformation

CasTeL

New Member
I'm trying to open XML file, add some changes, and save to other XML file result. I'm using standard javax.xml.parsers.* and javax.xml.transform* classes.But in saved documents, attributes in some elements are swapped, for example:Was:\[code\]<affiliation xml:id="curr1" countryCode="HU">\[/code\]And after transformation:\[code\]<affiliation countryCode="HU" xml:id="curr1">\[/code\]Elements "countryCode" and "xml:id" are swapped.Is any ways to restrict such attributes swapping? Code of opening/saving XML:\[code\]// Importsimport javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerConfigurationException;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult; // OpeningDocument document = getDocumentBuilder().parse(src);// SavinggetTransformer().transform(new DOMSource(document), new StreamResult(dst));private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { return documentBuilder == null ? documentBuilder = documentBuilderFactory.newDocumentBuilder() : documentBuilder;}private Transformer getTransformer() throws TransformerConfigurationException { return transformer == null ? transformer = transformerFactory.newTransformer() : transformer;}\[/code\]
 
Back
Top