List of utility methods to do XML Document Format
void | formatXML(Document xml, Document xsl, URIResolver resolver, Writer output) format XML try { DOMSource xslSource = new DOMSource(xsl); DOMSource xmlSource = new DOMSource(xml); Result result = new StreamResult(output); formatXML(xmlSource, xslSource, resolver, result); } finally { output.close(); |
void | pretty(Document document, OutputStream outputStream, int indent) pretty TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); ... |
void | prettyFormat(Document doc) As a workaround for javax.xml.transform.Transformer not being able to pretty print XML. prettyFormat(doc, DEFAULT_IDENT); |
String | prettyPrint(Document doc) pretty Print TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer; StringWriter writer = new StringWriter(); try { serializer = tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); serializer.transform(new DOMSource(doc), new StreamResult(writer)); ... |
void | prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath) pretty Print Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); Writer out = new FileWriter( new File(xmlTraDestinationFolderPath + programID.replaceAll("_", "-") + ".xml")); tf.transform(new DOMSource(doc), new StreamResult(out)); |
String | prettyPrint(final Document aNode) pretty Print DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impls = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSOutput domOutput = impls.createLSOutput(); domOutput.setEncoding(java.nio.charset.Charset.defaultCharset().name()); StringWriter writer = new StringWriter(); domOutput.setCharacterStream(writer); LSSerializer domWriter = impls.createLSSerializer(); DOMConfiguration domConfig = domWriter.getDomConfig(); ... |
void | prettyPrintXml(Document doc) pretty Print Xml TransformerFactory tranFactory = TransformerFactory.newInstance(); Transformer aTransformer = tranFactory.newTransformer(); Source src = new DOMSource(doc); Result dest = new StreamResult(System.out); aTransformer.transform(src, dest); |
String | prettyPrintXml(Document document) Pretty prints the document to string using default charset. return prettyPrintXml(document, "UTF-8"); |
String | prettyPrintXMLDocument(Node node) Create a pretty String representation of a DOM Document if (node == null) { return ""; DocumentBuilder builder = null; try { builder = getDocumentBuilder(); } catch (ParserConfigurationException exception) { System.err.println(exception); ... |
void | print(Document d)try { TransformerFactory xformFactory = TransformerFactory.newInstance(); javax.xml.transform.Transformer idTransform = xformFactory.newTransformer(); idTransform.setOutputProperty(OutputKeys.INDENT, "yes"); Source input = new DOMSource(d); Result output = new StreamResult(System.err); idTransform.transform(input, output); } catch (TransformerConfigurationException e) { ... |