문제

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