3
<?xml version="1.0" encoding="UTF-8"?><Request>

<Id>

here the first tag was written into file followed by xml version, i need that need to write in next line. like below

<?xml version="1.0" encoding="UTF-8"?>
 <Request>
  <Id>

i Have use below code to write the xml into file,please help

TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new File(
                Constants.xmlLocation
                        + Constants.metaDataXmlFileName
                        + format.format(calendar.getTime()) + ".xml"));

        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(
                "{http://xml.apache.org/xslt}indent-amount", "5");
        transformer.transform(source, result);
2

1 Answer 1

3

You can try the code below, this will work fine and you will be getting the formatted output

transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "10");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.