我希望在JAVA中清理XML的标题,如:
<?xml version="1.0" encoding="utf-8"?>
<Document>
...
到
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document document = builder.parse(new InputSource(new StringReader(strXmlContent)));
我有一个带有xml
的documentBuilderinterface MyInterface1 {}
interface MyInterface2 {}
现在我不知道怎么做才能做任何帮助?
答案 0 :(得分:2)
试试这个:
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
StreamResult result = new StreamResult( new StringWriter() );
DOMSource source = new DOMSource( document );
transformer.transform( source, result );
String xmlString = result.getWriter().toString();
System.out.println( xmlString );
要打印回来:
{{1}}