List of utility methods to do XML First Child Element
Element | getFirstChild(Element root, String name) Returns the first node that is a direct child of root with the coresponding name. NodeList nl = root.getChildNodes(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node node = nl.item(i); if (!(node instanceof Element)) continue; Element ele = (Element) node; if (ele.getTagName().equals(name)) ... |
Element | getFirstChild(Element tag, String childTagName) get First Child NodeList nodes = tag.getElementsByTagName(childTagName); if (nodes == null || nodes.getLength() == 0) { return null; return (Element) nodes.item(0); |
Element | getFirstChild(final Element el, final String name) Retrieves the given DOM element's first child element with the specified name. final NodeList nodes = el.getChildNodes(); final int len = nodes.getLength(); for (int i = 0; i < len; i++) { final Node node = nodes.item(i); if (!(node instanceof Element)) continue; final Element e = (Element) node; if (name == null || e.getTagName().equals(name)) ... |
Element | getFirstChild(final Element parent, final String childName) Gets the first child element node with the specified tag name of a specified parent node. final NodeList childrenList = parent.getChildNodes(); final int childrenCount = childrenList.getLength(); for (int i = 0; i < childrenCount; ++i) { final Node child = childrenList.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) child; if (childName.equals(element.getTagName())) { return element; ... |
Element | getFirstChild(final Element parentElem, final String childName) Gets the first child element with the specified name. NodeList childList = parentElem.getElementsByTagName(childName); if (childList.getLength() > 0) { Node childNode = childList.item(0); if (childNode instanceof Element && childNode.getParentNode() == parentElem) { return (Element) childNode; } else { return null; } else { return null; |
Node | getFirstChild(Node node, String childName) get First Child NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node child = nodeList.item(i); if (child.getNodeName().equals(childName)) { return child; return null; ... |
Element | getFirstChild(Node parent) Gets the first (direct) child Element. if (parent == null) return null; Node node = parent.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; node = node.getNextSibling(); return null; |
Element | getFirstChildByName(Element parent, String name) Return the first child element with a given name. NodeList children = parent.getElementsByTagName(name); if (children.getLength() == 0) { return null; return (Element) children.item(0); |
Node | getFirstChildByNodeName(Node parent, String nodeName) get First Child By Node Name for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) if (n.getNodeName().equals(nodeName)) return n; return null; |
Element | getFirstChildByNS(Element node, String ns, String localName) get First Child By NS Element e = null; NodeList nl = node.getElementsByTagNameNS(ns, localName); if (nl != null) { e = (Element) nl.item(0); return e; |