Java XML Element Value getElementValue(Element element, String tag)

Here you can find the source of getElementValue(Element element, String tag)

Description

get Element Value

License

Open Source License

Declaration

public static String getElementValue(Element element, String tag) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String getElementValue(Element element, String tag) {
        Element by = getElement(element, tag);
        if (!(by == null)) {
            return by.getFirstChild().getNodeValue();
        }//from  ww w .j ava  2  s . co  m
        return null;
    }

    public static Element getElement(Node node, String tag) {
        if (!node.hasChildNodes())
            return null;
        NodeList list = node.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            Node item = list.item(i);
            if (item instanceof Element) {
                Element element = (Element) item;
                if (element.getTagName().equals(tag))
                    return element;
            }
        }
        return null;
    }
}

Related

  1. getElementValue(Element element)
  2. getElementValue(Element element)
  3. getElementValue(Element element)
  4. getElementValue(Element element, String elementName)
  5. getElementValue(Element element, String name)
  6. getElementValue(Element element, String tagName)
  7. getElementValue(Element elm)
  8. getElementValue(Element p_element)
  9. getElementValue(Element root, String elemName)