Java XML Element to String elementToString(Element element)

Here you can find the source of elementToString(Element element)

Description

element To String

License

Open Source License

Declaration

public static String elementToString(Element element) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Element;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    public static String elementToString(Element element) {
        DOMImplementationLS lsImpl = (DOMImplementationLS) element.getOwnerDocument().getImplementation()
                .getFeature("LS", "3.0");
        LSSerializer serializer = lsImpl.createLSSerializer();
        serializer.getDomConfig().setParameter("xml-declaration", false); //by default its true, so set it to false to get String without xml-declaration
        return serializer.writeToString(element);
    }/* www. j av a  2 s . co  m*/
}

Related

  1. elementToStream(Element element, OutputStream out)
  2. elementToString(Element e)
  3. elementToString(Element el)
  4. elementToString(Element element)
  5. elementToString(Element element)
  6. elementToString(Element elt, String prefix)
  7. elementToString(final Element element)
  8. extractText(Element element)
  9. extractText(Element obj, String localName)