Here you can find the source of getFirstChildTag(Element el, String tag)
Parameter | Description |
---|---|
el | Element where to get children from |
tag | Tag to match |
null
if no match found.
static public Element getFirstChildTag(Element el, String tag)
//package com.java2s; /*//from w w w. j a va 2 s . c o m Copyright 2013, 2016 Nationale-Nederlanden Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Method getFirstChildTag. Return the first child-node which is an element * with tagName equal to given tag. * This method only looks at the direct children of the given node, and * doesn't descent deeper into the tree. * * @param el Element where to get children from * @param tag Tag to match * @return Element The element found, or <code>null</code> if no match * found. */ static public Element getFirstChildTag(Element el, String tag) { NodeList nl; int len; nl = el.getChildNodes(); len = nl.getLength(); for (int i = 0; i < len; ++i) { Node n = nl.item(i); if (n instanceof Element) { Element elem = (Element) n; if (elem.getTagName().equals(tag)) { return elem; } } } return null; } }