List of utility methods to do XML Format
void | printStream(InputStream is) print Stream StreamSource source = new StreamSource(is); String msgString = null; try { Transformer xFormer = TransformerFactory.newInstance().newTransformer(); xFormer.setOutputProperty("omit-xml-declaration", "yes"); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Result result = new StreamResult(outStream); xFormer.transform(source, result); ... |
String | printXML(Node node) Transforms an XML to a String TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer; try { serializer = tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); StringWriter output = new StringWriter(); serializer.transform(new DOMSource(node), new StreamResult(output)); ... |
String | xmlFormat(String xml) xml Format return xmlFormat(xml, 4);
|
String | xmlFormat(String xml) xml Format StringWriter writer; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xml))); DOMSource source = new DOMSource(doc); writer = new StringWriter(); ... |