Java XML Element Get from Parent getElementStringValue(Document document, Element parent, String element)

Here you can find the source of getElementStringValue(Document document, Element parent, String element)

Description

get Element String Value

License

Apache License

Declaration

public static String getElementStringValue(Document document, Element parent, String element) 

Method Source Code

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

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getElementStringValue(Document document, Element parent, String element) {
        NodeList nl = parent.getElementsByTagName(element);
        if (nl.getLength() == 0) {
            return "";
        }/*from   www .j a va2 s .c  o m*/

        Node n = nl.item(0).getFirstChild();
        if (n == null) {
            return "";
        }

        return n.getNodeValue();
    }
}

Related

  1. getElementIntValue(Document document, Element parent, String string)
  2. getElements(Document document, Element parent)
  3. getElements(Document document, Element parent)
  4. getElementValueByTagName(Document doc, String parentName, String eleName)
  5. getFirstElement(Node parent)
  6. getFirstElement(Node parent)
  7. getFirstNode(final Node parent, final String... path)