Java XML Node Text Value getTagValue(Node node, String name)

Here you can find the source of getTagValue(Node node, String name)

Description

get Tag Value

License

BSD License

Declaration

public static String getTagValue(Node node, String name) 

Method Source Code


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

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

public class Main {
    public static String getTagValue(Node node, String name) {

        if (node.getNodeType() == Node.ELEMENT_NODE) {

            Element el = (Element) node;
            NodeList nodeList = el.getElementsByTagName(name);
            if (nodeList.getLength() > 0) {
                el = (Element) nodeList.item(0);
                nodeList = el.getChildNodes();

                if (nodeList.getLength() > 0) {
                    return ((Node) nodeList.item(0)).getNodeValue();
                }/* w w w  .  ja va  2s.  co  m*/
            }

        }
        return "";
    }
}

Related

  1. getString(final Node node, final String default_value)
  2. getString(Node node)
  3. getStringValue(NamedNodeMap values, String name)
  4. getStringValue(Node node)
  5. getStringValue(Node node)
  6. getTagValueWithoutNamespace(Node n)
  7. getText(final Node node)
  8. getText(final Node xmlNode)
  9. getText(Node elem)