Java XML Element to String getStringRepresentation(Element element)

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

Description

Gets the string representation for the given XML element, including tag and attributes.

License

LGPL

Parameter

Parameter Description
element the element to get the string representation for

Return

the string representation for the given element

Declaration

public static String getStringRepresentation(Element element) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import org.w3c.dom.Element;

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

public class Main {
    /**/*from   ww  w . j  a  v a 2 s . c o  m*/
     * Gets the string representation for the given XML element, including tag and attributes.
     *
     * @param element the element to get the string representation for
     * @return the string representation for the given element
     */
    public static String getStringRepresentation(Element element) {
        DOMImplementationLS implementation = (DOMImplementationLS) element.getOwnerDocument().getImplementation();
        LSSerializer lsSerializer = implementation.createLSSerializer();
        lsSerializer.getDomConfig().setParameter("xml-declaration", false);
        return lsSerializer.writeToString(element);
    }
}

Related

  1. getString(final Element element)
  2. getStringByTagName(Element element, String tag)
  3. getStringFromParagraphElement(Element element)
  4. getStringOptionsList(final Element configuration, final String optionPrefix, final String option)
  5. getStringProperty(Element properties, String name)
  6. getStringValue(Element el)
  7. getStringValue(Element ele, String tagName)
  8. getStringValue(Element element, String tagName)
  9. getStringValue(Element from)