Java XML Element Get getElementContent(final Element element, final boolean trim)

Here you can find the source of getElementContent(final Element element, final boolean trim)

Description

get Element Content

License

Apache License

Declaration

public static String getElementContent(final Element element, final boolean trim) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;

public class Main {
    public static String getElementContent(final Element element, final boolean trim) {
        final NodeList nl = element.getChildNodes();
        String attributeText = "";
        for (int i = 0; i < nl.getLength(); i++) {
            final Node n = nl.item(i);
            if (n instanceof Text) {
                attributeText += ((Text) n).getData();
            }/*from www . j  ava2 s .  co m*/
        }
        if (trim) {
            attributeText = attributeText.trim();
        }
        return attributeText;
    }
}

Related

  1. getElementContent(Element elem)
  2. getElementContent(Element element, String defaultStr)
  3. getElementContent(Element element, String defaultStr)
  4. getElementContent(final Element el)
  5. getElementContent(final Element element)
  6. getElementContents(Element element, String elementName)
  7. getElementDescendant(Element elem, String ns_uri, String tagName)
  8. getElementForLine(Document document, int line)
  9. getElementId(Element element)