List of utility methods to do XML Format
String | prettyXml(String xml) pretty Xml TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer; try { Source source = new StreamSource(new StringReader(xml)); StringWriter writer = new StringWriter(); serializer = tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); ... |
String | prettyXml(String xml) pretty Xml Transformer serializer; try { Source source = new StreamSource(new StringReader(xml)); StringWriter writer = new StringWriter(); serializer = transFactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); serializer.transform(source, new StreamResult(writer)); ... |
String | prettyXml(String xml) Uses the Xalan javax.transform classes to indent an XML string properly so that it is easier to read. StringWriter out = new StringWriter(); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); StreamResult result = new StreamResult(out); ... |
void | prettyXmlPrint(Node xml, OutputStream out) pretty Xml Print Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(xml), new StreamResult(out)); |
void | print(Element elm, OutputStream out) Print part of document TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(elm); StreamResult result = new StreamResult(out); transformer.transform(source, result); |
void | print(File file)Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new StreamSource(file), new StreamResult(System.out)); |
void | print(Node node) Print a DOM to standard out. if (node == null) { System.out.println("DOMUtils.print: Null node"); return; try { DOMSource ds = new DOMSource(node); StreamResult result = new StreamResult(System.out); TransformerFactory transFact = TransformerFactory.newInstance(); ... |
String | print(Node node)try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty("omit-xml-declaration", "yes"); DOMSource source = new DOMSource(node); ByteArrayOutputStream os = new ByteArrayOutputStream(2000); StreamResult result = new StreamResult(os); transformer.transform(source, result); ... |
void | print(Node node, OutputStream out)TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new DOMSource(node), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); ... |
String | print(Node node, String encoding) Prints a Node tree recursively. if (node == null) { return null; try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty("omit-xml-declaration", "yes"); transformer.setOutputProperty("encoding", encoding); ... |