如何使用 XMLSerializer 正确缩进 XML?
2022-09-03 16:49:41
我很难尝试使用缩进XML文件。XMLSerializer
我试过了
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output",
true);
我试图追加到,但输出是文件开头的's和's,而不是在正确的位置。我已经尝试了正确的URI等。\n
FileWriter
\n
\t
setPropery
部分代码:
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
parserFactory .setNamespaceAware(true);
XmlSerializer serializer = parserFactory .newSerializer();
File xmlFile = new File(PATH + ".xml");
FileWriter writer = new FileWriter(xmlFile);
serializer.setOutput(writer);
//serializer.setProperty(INDENT_URL, INDENT);
serializer.startDocument("UTF-8", null);
//serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output",
true);
serializer.startTag(null, "bla");
writer.append('\n');
我错过了什么?