List of utility methods to do XML First Child Element
Element | getFirstChildByRegex(Element ele, String pattern) get First Child By Regex NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && getLocalName(node).matches(pattern)) { return (Element) node; return null; ... |
Element | getFirstChildByTagName(Element parent, String tagName) get First Child By Tag Name NodeList nodes = parent.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(tagName)) { return (Element) node; return null; ... |
Element | getFirstChildByTagName(Node parent, String tagName) get First Child By Tag Name List<Element> children = getChildrenByTagName(parent, tagName);
return (children.size() == 0) ? null : children.get(0);
|
Node | getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag) returns the first child of the contextnode which has the specified tagname and namespace uri regardless of the depth in the tree. Node n = null; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { n = ((Document) contextNode).getDocumentElement(); if (!(n.getNamespaceURI().equals(nsuri) && n.getNodeName().equals(tag))) { n = null; } else { NodeList nodes = ((Element) contextNode).getElementsByTagNameNS(nsuri, tag); ... |
Node | getFirstChildByType(Element element, int nodeType) get First Child By Type NodeList children = element.getChildNodes(); int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node child = children.item(i); if (child.getNodeType() == nodeType) { return child; return null; |
Node | getFirstChildByType(Element element, short nodeType) get First Child By Type NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == nodeType) { return childNodes.item(i); return null; |
Element | getFirstChildElement(@Nonnull final Node aStartNode) Get the first direct child element of the passed element. final NodeList aNodeList = aStartNode.getChildNodes(); final int nLen = aNodeList.getLength(); for (int i = 0; i < nLen; ++i) { final Node aNode = aNodeList.item(i); if (aNode.getNodeType() == Node.ELEMENT_NODE) return (Element) aNode; return null; ... |
Element | getFirstChildElement(Element e) Get the first child of e which is an element, or null if there is no such element.
Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); return (Element) n; |
Element | getFirstChildElement(Element e) Gets the first child element. if (e != null) { NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { return (Element) node; return null; |
Element | getFirstChildElement(Element e) Get the first child of e which is an element, or null if there is no such element.
Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); return (Element) n; |