Question

I have created a conversion tool to add some information to an existing xml file. This is done by using DOM and the Transformer class. The output file will be processed by third party software. This TPS needs the empty tags from the input and outputfile in Long Notation.

Unfortunately, transformer class always change them to short notation. Is there a way to prevent this from happenning?

I have been searching various sites, but haven't found a solution that really fits my needs.

Please help, Thanks, Kind regards, Maarten

Was it helpful?

Solution

You can transform the DOM to StAXResult.

For instance,

 XMLOutputFactory factory=XMLOutputFactory.newFactory();
 XMLStreamWriter writer=factory.createXMLStreamWriter(System.out);
 StAXResult result=new StAXResult(writer);
 trans.transform(new DOMSource(doc),result);

OTHER TIPS

                XMLOutputFactory factory = XMLOutputFactory.newFactory();
                XMLStreamWriter writer = factory.createXMLStreamWriter(System.out);
                StAXResult result = new StAXResult(writer);
                TransformerFactory transformerFactory = TransformerFactory.newInstance();
                Transformer transformer = transformerFactory.newTransformer();
                transformer.transform(new DOMSource(doc), result);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top