Domanda

I have created a xml with Xml bean and now it's time to write the created xml in a file. But when I am writing my file in the xml file it's unformatted. So, I need to help to write the formatted xml into the file. My Code is given below:

document contains the xml and it's a object of org.apache.xmlbeans.XmlObject

File file = new File("test.xml");
document.save(file);
È stato utile?

Soluzione

XmlBeans.save() uses toString() to get the XML string, which is not formatted. Due to this the string in your file is unformatted as well. For formatted output do the following:

XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
document.save(file, xmlOptions);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top