XmlWriter extends DefaultHandler implements LexicalHandler { @Override public String toString() { return writer.toString(); } XmlWriter();  XmlWriter(Writer writer);  XmlWriter(OutputStream stream); @Override void startDocument(); @Override void endDocument(); @Override void startPrefixMapping(String prefix, String uri); @Override void startElement(String uri, String localName, String qName, Attributes attributes); @Override void endElement(String uri, String localName, String qName); @Override void characters(char[] ch, int start, int length); @Override void comment(char[] ch, int start, int length); @Override void processingInstruction(String target, String data); @Override void startDTD(String arg0, String arg1, String arg2); @Override void endDTD(); @Override void startCDATA(); @Override void endCDATA(); @Override void startEntity(String arg0); @Override void endEntity(String arg0); Writer getWriter(); @Override String toString(); void setIncludeXmlDeclaration(boolean includeXmlDeclaration); void setNewlineAfterXmlDeclaration(boolean newlineAfterXmlDeclaration); void setIncludeComments(boolean includeComments); void setTextMode(boolean textMode);  }
@Test public void testBasic() throws Exception { String input = TestFileUtils.getTestFile("/Xslt/AnyXml/in.xml"); String expected = input; XmlWriter xmlWriter = new XmlWriter(); XmlUtils.parseXml(input, xmlWriter); assertEquals(expected,xmlWriter.toString()); }
@Test public void testNoLexicalHandling() throws Exception { String input = TestFileUtils.getTestFile("/Xslt/AnyXml/in.xml"); String expected = TestFileUtils.getTestFile("/Xslt/AnyXml/NoComments.xml"); XmlWriter xmlWriter = new XmlWriter(); InputSource inputSource = new InputSource(new StringReader(input)); XMLReader xmlReader = XmlUtils.getXMLReader(xmlWriter); xmlReader.setProperty("http: xmlReader.parse(inputSource); assertEquals(expected,xmlWriter.toString()); }