List of utility methods to do XML Node to String
String | nodeToString(Node node) node To String String textContent = node.getTextContent(); StringBuilder buf = new StringBuilder(); if (textContent != null) { short nodeType = node.getNodeType(); switch (nodeType) { case Node.TEXT_NODE: { buf.append(textContent); break; ... |
String | nodeToString(Node node, boolean pretty) See documentToString. return nodeToString(node, (pretty ? 0 : -1));
|
String | nodeToString(Node node, Set node To String StringBuilder b = new StringBuilder(); if (node == null) { return ""; if (node instanceof Element) { Element element = (Element) node; b.append("<"); b.append(element.getNodeName()); ... |
void | nodeToString(Node node, StringBuffer buf) node To String TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource dSource = new DOMSource(node); StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(dSource, sr); StringWriter anotherSW = (StringWriter) sr.getWriter(); ... |
void | nodeToString(Node node, StringBuffer sb) node To String int type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: sb.append("<?xml version=\"1.0\" ?>"); nodeToString(((Document) node).getDocumentElement(), sb); break; case Node.ELEMENT_NODE: sb.append("<"); ... |
String | nodeToString(Object node) node To String String result = ""; if (node instanceof String) { String str = ((String) node).replaceAll("\\s+", " ").trim(); result += str; } else if (node instanceof Text) { String str = ((Text) node).getTextContent().replaceAll("\\s+", " ").trim(); result += str; } else if (node instanceof Element) { ... |
String | nodeToString(org.w3c.dom.Node domNode) node To String if (domNode == null) { return ""; String s = typeName[domNode.getNodeType()]; String nodeName = domNode.getNodeName(); if (!nodeName.startsWith("#")) { s += ": " + nodeName; if (domNode.getNodeValue() != null) { if (s.startsWith("ProcInstr")) s += ", "; else s += ": "; String t = domNode.getNodeValue().trim(); int x = t.indexOf("\n"); if (x >= 0) t = t.substring(0, x); s += t; return s; |
String | nodeToText(Node node) node To Text StringBuffer buffer = new StringBuffer(); if (node instanceof Text) { Text text = (Text) node; buffer.append(text.getData()); buffer.append(' '); } else { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { ... |
void | nodeToWriter(Node node, Writer writer) node To Writer TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "no"); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(writer); ... |
String | nodeToXmlString(Node node) Returns an XML representation of the provided node. try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(new StringWriter()); t.transform(source, result); return result.getWriter().toString(); } catch (TransformerException e) { ... |