@Test public void testConverXmlDocToString_3() throws Exception { Document document = readDocument("src/test/resources/xmlDocument.txt"); String docString = documentXmlConverter.convertXmlDocToString(document); logger.debug(docString); assertNotNull(docString); String s3 = fileReader.readFile("xmlString3.txt"); assertTrue(XmlComparator.compareXMLs(s3, docString, Arrays.asList("")) .similar()); }
@Override public String convertXmlDocToString(Document xmlDocument) throws DocumentXmlConverterException { String xmlString = ""; TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty( "{http: StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xmlDocument), new StreamResult( writer)); xmlString = writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { throw new DocumentXmlConverterException(e); } return xmlString; }
DocumentXmlConverterImpl implements DocumentXmlConverter { @Override public String convertXmlDocToString(Document xmlDocument) throws DocumentXmlConverterException { String xmlString = ""; TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty( "{http: StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xmlDocument), new StreamResult( writer)); xmlString = writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { throw new DocumentXmlConverterException(e); } return xmlString; } }
DocumentXmlConverterImpl implements DocumentXmlConverter { @Override public String convertXmlDocToString(Document xmlDocument) throws DocumentXmlConverterException { String xmlString = ""; TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty( "{http: StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xmlDocument), new StreamResult( writer)); xmlString = writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { throw new DocumentXmlConverterException(e); } return xmlString; }  }
DocumentXmlConverterImpl implements DocumentXmlConverter { @Override public String convertXmlDocToString(Document xmlDocument) throws DocumentXmlConverterException { String xmlString = ""; TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty( "{http: StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xmlDocument), new StreamResult( writer)); xmlString = writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { throw new DocumentXmlConverterException(e); } return xmlString; }  @Override Document loadDocument(String xmlString); @Override String convertXmlDocToString(Document xmlDocument); }
DocumentXmlConverterImpl implements DocumentXmlConverter { @Override public String convertXmlDocToString(Document xmlDocument) throws DocumentXmlConverterException { String xmlString = ""; TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty( "{http: StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xmlDocument), new StreamResult( writer)); xmlString = writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { throw new DocumentXmlConverterException(e); } return xmlString; }  @Override Document loadDocument(String xmlString); @Override String convertXmlDocToString(Document xmlDocument);  }