Java XML Child Get by Name getChildElement(Node start, String name)

Here you can find the source of getChildElement(Node start, String name)

Description

__UNDOCUMENTED__

License

BSD License

Parameter

Parameter Description
start __UNDOCUMENTED__
name __UNDOCUMENTED__

Return

__UNDOCUMENTED__

Declaration

public static Element getChildElement(Node start, String name) 

Method Source Code


//package com.java2s;
/*//from w w w  .  j ava  2  s.com
 * Copyright (c) 2012. betterFORM Project - http://www.betterform.de
 * Licensed under the terms of BSD License
 */

import org.w3c.dom.*;

public class Main {
    /**
     * __UNDOCUMENTED__
     *
     * @param start __UNDOCUMENTED__
     * @param name  __UNDOCUMENTED__
     * @return __UNDOCUMENTED__
     */
    public static Element getChildElement(Node start, String name) {
        //        NodeList nl=start.getChildNodes();
        NodeList nl = null;

        if (start.getNodeType() == Node.DOCUMENT_NODE) {
            nl = ((Document) start).getDocumentElement().getChildNodes();
        } else {
            nl = start.getChildNodes();
        }

        int len = nl.getLength();
        Node n = null;

        for (int i = 0; i < len; i++) {
            n = nl.item(i);

            if (n.getNodeType() == Node.ELEMENT_NODE) {
                if (n.getNodeName().equals(name)) {
                    return (Element) n;
                }
            }
        }

        return null;
    }
}

Related

  1. getChildElement(Node node, String childName)
  2. getChildElement(Node parent, String childLocalName, String childNamespaceURI)
  3. getChildElement(Node parent, String childName)
  4. getChildElement(Node parent, String elementName)
  5. getChildElement(Node parent, String name)
  6. getChildElement(NodeList childs, Node parent)
  7. getChildElement(String name, Element el)
  8. getChildElement(String name, Element elem)
  9. getChildElements(Element element, String childrenName)