How to formate the xml in java dom parser? -


this question has answer here:

<?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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -