Add xml-stylesheet and get standalone = yes Add xml-stylesheet and get standalone = yes xml xml

Add xml-stylesheet and get standalone = yes


I added

doc.setXmlStandalone(true);ProcessingInstruction pi = doc.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"my.stylesheet.xsl\"");`  

before the cut and

doc.insertBefore(pi, root);

right after the root element was appended to the doc.


in my code, I wrote :


DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();Document document = builder.newDocument();document.setXmlStandalone(true);

TransformerFactory tfactory = TransformerFactory.newInstance();Transformer transformer = tfactory.newTransformer();transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");

output:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>