List of utility methods to do XML Element to String
String | getStringValue(Element from) get String Value String value = from.getFirstChild().getNodeValue();
return value;
|
String | getStringValue(final Element element) Get element node string value. final StringBuilder buf = new StringBuilder(); final NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node n = children.item(i); switch (n.getNodeType()) { case Node.TEXT_NODE: buf.append(n.getNodeValue()); break; ... |
String | getStringValueByTagName(Element element, String tagName) get String Value By Tag Name NodeList nl1 = element.getElementsByTagName(tagName); if (nl1.getLength() <= 0) { return null; Element el = (Element) nl1.item(0); return el.getChildNodes().item(0).getNodeValue(); |
String | getStringValueOfElement(Element elem) Exactly like value-of() StringBuffer buf = new StringBuffer(); NodeList nodes = elem.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); switch (node.getNodeType()) { case Node.TEXT_NODE: buf.append(((Text) node).getData()); break; ... |
List | getStringValues(Element from, String elementName) get String Values List<String> values = new LinkedList<String>(); NodeList nodes = from.getElementsByTagName(elementName); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { values.add(nodes.item(i).getChildNodes().item(0).getNodeValue()); return values; ... |
String | getXmlString(Element node) get Xml String return toString(node);
|
String | getXMLStringFromNode(Element node) get XML String From Node DOMSource domSource = new DOMSource(node); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return result.getWriter().toString(); |
String | toString(Element e) to String try { TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer xform = tfactory.newTransformer(); Source src = new DOMSource(e); java.io.StringWriter writer = new StringWriter(); Result result = new javax.xml.transform.stream.StreamResult(writer); xform.transform(src, result); return writer.toString(); ... |
String | toString(Element element) Transform an Element into a String .
try { ByteArrayOutputStream out = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Source source = new DOMSource(element); Result target = new StreamResult(out); transformer.transform(source, target); return out.toString("UTF-8"); ... |
String | toString(Element node) to String TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(buffer)); return buffer.toString(); |