質問

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);
役に立ちましたか?

解決

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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top