List of utility methods to do XML First Child Element
String | getFirstChildTextValue(Element parent, String childName) get First Child Text Value NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { Element elem = (Element) child; if (childName.equals(elem.getNodeName())) { return getOrCreateFirstTextChild(elem).getTextContent(); return null; |
Element | getFirstChildWithTagName(Element parent, String tagName) get First Child With Tag Name final NodeList elements = parent.getElementsByTagName(tagName); return (elements.getLength() > 0) ? (Element) (elements.item(0)) : null; |
Element | getFirstChildWithTagName(Node data, String tagName) The function getFirstChildWithTagName() returns the first child node from a node, identified by its node name. for (Node element = data.getFirstChild(); element != null; element = element.getNextSibling()) { if (!(element instanceof Element)) { continue; if (element.getNodeName().equals(tagName)) { return (Element) element; throw new NoSuchElementException(tagName); |
Element | getFirstElement(Element element, String childName) get First Element NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element && ((Element) child).getTagName().equals(childName)) { return (Element) child; return null; ... |
Element | getFirstElementChild(Element aElement) Gets the first DOM Element Node of the aElement DOM Element.
NodeList children = aElement.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { return (Element) children.item(i); return null; |
Element | getFirstElementChild(Element element) get First Element Child Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) return (Element) child; child = child.getNextSibling(); return null; |
Element | getFirstElementChild(Element elemNode) Returns the first element node within the children of the specified element. NodeList nl = elemNode.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node cand = nl.item(i); if (cand.getNodeType() == Node.ELEMENT_NODE) { return (Element) cand; return null; ... |
Element | getFirstElementChild(Element elemNode) Returns the first element node within the children of the specified element. NodeList nl = elemNode.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node cand = nl.item(i); if (cand.getNodeType() == Node.ELEMENT_NODE) { return (Element) cand; return null; ... |
Element | getFirstElementChild(Element parent) Finds the first element child, or null if not found. for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) return (Element) n; return null; |
Element | GetFirstElementChild(Element tag) Get First Element Child Node n = tag.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); Element e = (Element) n; return e; |