List of utility methods to do XML Document Format
void | printDoc(Document doc) print Doc try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(doc), new StreamResult(System.out)); } catch (Exception ex) { new RuntimeException(ex); |
void | printDoc(Document doc, PrintStream pstrm) print Doc String version = "1.0"; String encoding = null; pstrm.print("<?xml version=\"" + version + "\""); if (encoding == null) { pstrm.println("?>"); } else { pstrm.println(" encoding=\"" + encoding + "\"?>"); printPI(doc, pstrm); pstrm.println(""); printDoctype(doc, pstrm); pstrm.println("\n"); printElem(doc.getDocumentElement(), "", true, pstrm); |
void | printDoctype(Document doc, PrintStream pstrm) print Doctype if (doc.getDoctype() != null) { pstrm.println("<!DOCTYPE " + doc.getDoctype().getName()); String pubid = doc.getDoctype().getPublicId(); if (pubid != null) { pstrm.print("\tPUBLIC \"" + pubid + "\""); String sysid = doc.getDoctype().getSystemId(); if (sysid != null) { ... |
void | printDocument(Document d) Prints the specified document. printNode(d.getDocumentElement(), 0); |
String | printDocument(Document doc, boolean prettyPrint) print Document ByteArrayOutputStream baos = new ByteArrayOutputStream(); printDocument(doc, baos, prettyPrint); return new String(baos.toByteArray()); |
void | printDocument(Document doc, OutputStream out) print Document TransformerFactory tf = TransformerFactory.newInstance(); 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"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); ... |
void | printDocument(Document doc, Writer ps) Print the XML document try { String lineSeparator = System.getProperty("line.separator"); ps.write("<?xml version=\"1.0\"?>"); ps.write(lineSeparator); ps.write(lineSeparator); Element node = doc.getDocumentElement(); printTree(ps, node, "", lineSeparator); } catch (IOException e) { ... |
void | printDocument(Document document) prints the given document to system.out try { transformer.transform(new DOMSource(document), new StreamResult(System.out)); } catch (TransformerException e) { System.err.println("printDocument failed cause of " + e); |
void | printDocument(Document document) Print a DOM document to stdout. serializeDocument(document, System.out); |
String | printDocument(Document document) print Document StringWriter writer = new StringWriter(); try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(document), new StreamResult(writer)); return writer.toString(); } finally { ... |