Utils.java Source code

Java tutorial

Introduction

Here is the source code for Utils.java

Source

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

public class Utils {

    /**
     * Return a list of named Elements.
     * @param element the containing Element
     * @param name the tag name
     * @return NodeList of matching elements
     */
    public static NodeList getElementList(Element element, String name) {
        return element.getElementsByTagName(name);
    }

    /**
     * Return the first named Element found.  Null if none.
     * @param element the containing Element
     * @param name the tag name
     * @return matching Element (null if none)
     */
    public static Element getElement(Element element, String name) {
        NodeList nodeList = getElementList(element, name);
        return (nodeList.getLength() == 0) ? null : (Element) nodeList.item(0);
    }

}