List of utility methods to do XML Element to String
void | elementToStream(Element element, OutputStream out) Write the content of a DOM element to the provided outputstream DOMSource source = new DOMSource(element); StreamResult result = new StreamResult(out); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.transform(source, result); |
void | elementToStream(Element element, OutputStream out) element To Stream DOMSource source = new DOMSource(element); StreamResult result = new StreamResult(out); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.transform(source, result); |
String | elementToString(Element e) element To String StringBuffer buf = new StringBuffer(); buf.append(e.getTagName()).append("{"); for (int i = 0; i < e.getAttributes().getLength(); i++) { if (i > 0) { buf.append(", "); Node n = e.getAttributes().item(i); buf.append(attributeName((Attr) n)).append("=").append(n.getNodeValue()); ... |
String | elementToString(Element el) element To String if (el == null) return ""; Document document = el.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); return serializer.writeToString(el); |
String | elementToString(Element element) element To String DOMImplementationLS lsImpl = (DOMImplementationLS) element.getOwnerDocument().getImplementation() .getFeature("LS", "3.0"); LSSerializer serializer = lsImpl.createLSSerializer(); serializer.getDomConfig().setParameter("xml-declaration", false); return serializer.writeToString(element); |
String | elementToString(Element element) element To String Document document = element.getOwnerDocument();
DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
LSSerializer serializer = domImplLS.createLSSerializer();
String result = serializer.writeToString(element);
return result;
|
String | elementToString(Element element) Converts an Element object into String representation DOMSource domSource = new DOMSource(element); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, streamResult); return stringWriter.toString(); ... |
String | elementToString(Element elt, String prefix) element To String String str = prefix + "<" + elt.getNodeName(); return str; |
String | elementToString(final Element element) Converts an Element into its XML String representation. try { final DOMSource domSource = new DOMSource(element); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); ... |
String | extractText(Element element) extract Text NodeList children = element.getChildNodes(); int length = children.getLength(); for (int n = 0; n < length; ++n) { Node next = children.item(n); if (next.getNodeType() == Node.TEXT_NODE) return next.getNodeValue().trim(); return null; ... |