List of utility methods to do XML Document Print
String | printDocument(File file) print Document BufferedReader br = new BufferedReader(new FileReader(file)); String line = null, fileContent = ""; while ((line = br.readLine()) != null) { fileContent += line + "--"; return fileContent; |
void | printDocument(final Document doc) print Document try { final TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; 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"); ... |
void | printDocument(Node _docOrNode, OutputStream _outStream) Dump a Document or Node -compatible object to the given OutputStream (e.g. if (_docOrNode == null || _outStream == null) { throw new IOException("Cannot print (on) 'null' object"); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ... |
String | printDocument(Node doc) print Document 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"); StringWriter sw = new StringWriter(); ... |
void | printDocumentToStdout(final Document document) print Document To Stdout final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); final StreamResult result = new StreamResult(new StringWriter()); final DOMSource source = new DOMSource(document); transformer.transform(source, result); final String xmlString = result.getWriter().toString(); System.out.println(xmlString); |
void | printDocumentTree(Node el) print Document Tree System.out.println(el.toString()); for (int i = 0; i < el.getChildNodes().getLength(); i++) printDocumentTree(el.getChildNodes().item(i)); |
void | printDOM(File file, Document doc, String encoding) print DOM printDOM(file != null ? new FileOutputStream(file) : System.out, doc, encoding); System.err.println("File " + file + " written."); |
void | printElements(Document doc) print Elements NodeList nodelist = doc.getElementsByTagName("*"); Node node; for (int i = 0; i < nodelist.getLength(); i++) { node = nodelist.item(i); System.out.print(node.getNodeName() + " "); System.out.println(); |
String | printElements(Document dom) print Elements if (dom == null) return null; StringBuffer sb = new StringBuffer(); walkNodes(dom, sb, ""); return sb.toString(); |
void | printPI(Document doc, PrintStream pstrm) print PI NodeList nodes = doc.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; pstrm.println("<?" + pi.getTarget() + " " + pi.getData() + "?>"); |