Java XML First Child Element getFirstMatchedValueByChildTagName(Node parent, String name)

Here you can find the source of getFirstMatchedValueByChildTagName(Node parent, String name)

Description

get First Matched Value By Child Tag Name

License

Apache License

Declaration

public static String getFirstMatchedValueByChildTagName(Node parent, String name) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static String getFirstMatchedValueByChildTagName(Node parent, String name) {
        //List<Element> nodeList = new ArrayList<Element>();
        for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
            //System.out.println(child.getNodeName());
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (child.getNodeName().indexOf(name) != -1) {
                    return child.getTextContent();
                } else {
                    String value = getFirstMatchedValueByChildTagName((Element) child, name);
                    if (value != null) {
                        return value;
                    }/*ww w.ja  v  a  2s  .co m*/
                }
            }
        }
        return null;
    }
}

Related

  1. getFirstLevelChildElementByTagName(Element parent, String elementName)
  2. getFirstLevelChildElements(Element parent)
  3. getFirstLevelChildElements(Element parent)
  4. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  5. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  6. getFirstMatchingDeepChildByTagName(final Element e, final String tagName)
  7. getFirstNamedChild(Node n, String name)
  8. getFirstNamedChild(Node node, String name)
  9. getFirstNamedChildNode(Element element, String string)