How to formate the xml in java dom parser? -
this question has answer here:
- how pretty print xml java? 29 answers
<?xml version="1.0" encoding="utf-8"?><request> <id>
here first tag written file followed xml version, need need write in next line. below
<?xml version="1.0" encoding="utf-8"?> <request> <id>
i have use below code write xml 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);
you can try code, work fine , getting formatted output
transformer.setoutputproperty(outputkeys.indent, "yes"); transformer.setoutputproperty(outputkeys.doctype_public,"yes"); transformer.setoutputproperty("{http://xml.apache.org/xslt}indent-amount", "10");
Comments
Post a Comment