Java Utililty Methods XML Element to String

List of utility methods to do XML Element to String

Description

The list of methods to do XML Element to String are organized into topic(s).

Method

StringgetString(Element xmlElement)
get String Data
Node node = xmlElement.getFirstChild();
if (node == null)
    return "";
if (node instanceof Text) {
    Text text = (Text) node;
    if (text.getData() == null)
        return "";
    else
...
StringgetString(final Element element)
Get string value of an element.
final Node text = element.getFirstChild();
if (text == null) 
    return "";
if ((text.getNodeType() == Node.TEXT_NODE || text.getNodeType() == Node.CDATA_SECTION_NODE))
    return text.getNodeValue();
return "";
StringgetStringByTagName(Element element, String tag)
get String By Tag Name
return getStringFromElement(getByTagAndIndex(element, tag, 0));
StringgetStringFromParagraphElement(Element element)
get String From Paragraph Element
StringBuffer value = new StringBuffer();
NodeList nl = element.getElementsByTagName("p");
for (int i = 0; i < nl.getLength(); i++) {
    NodeList children = nl.item(i).getChildNodes();
    for (int c = 0; c < children.getLength(); c++) {
        if (children.item(c) instanceof Text) {
            value.append(((Text) children.item(c)).getData());
    if (i != nl.getLength() - 1) {
        value.append("\n");
return value.toString();
String[]getStringOptionsList(final Element configuration, final String optionPrefix, final String option)
get String Options List
String[] optionsList = new String[0];
Element optionsElement = null;
try {
    optionsElement = (Element) configuration.getElementsByTagName(optionPrefix).item(0);
} catch (NullPointerException e) {
    return optionsList;
String[] skiped = null;
...
StringgetStringProperty(Element properties, String name)
get String Property
return getPropertyNode(properties, name).getAttributes().getNamedItem(STRING_ATTR).getNodeValue();
StringgetStringRepresentation(Element element)
Gets the string representation for the given XML element, including tag and attributes.
DOMImplementationLS implementation = (DOMImplementationLS) element.getOwnerDocument().getImplementation();
LSSerializer lsSerializer = implementation.createLSSerializer();
lsSerializer.getDomConfig().setParameter("xml-declaration", false);
return lsSerializer.writeToString(element);
StringgetStringValue(Element el)
get String Value
return getStringValue(el, true);
StringgetStringValue(Element ele, String tagName)
get String Value
String value = null;
NodeList nl = ele.getElementsByTagName(tagName);
if (nl != null && nl.getLength() > 0) {
    Element el = (Element) nl.item(0);
    value = el.getFirstChild().getNodeValue();
return value;
StringgetStringValue(Element element, String tagName)
get String Value
String textValue = null;
NodeList nl = element.getElementsByTagName(tagName);
if (nl != null && nl.getLength() > 0) {
    Element el = (Element) nl.item(0);
    textValue = el.getFirstChild().getNodeValue();
return textValue;