List of utility methods to do XML First Child Element
Element | getFirstElementChild(final Element element, final String namespace, final String localname) get First Element Child Node node = element.getFirstChild(); if (node == null) { return null; do { if (match(node, namespace, localname)) { return (Element) node; } while ((node = node.getNextSibling()) != null); return null; |
Node | getFirstElementChild(final Node node) Returns the first child node that is an element (type == ELEMENT_NODE). final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { return child; return null; ... |
Element | getFirstElementChild(final Node node) get First Element Child Element elem = null; for (Node childNode = node.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { elem = (Element) childNode; return elem; return elem; ... |
Element | getFirstElementChild(Node root) get First Element Child Node node = root.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { return (Element) node; node = node.getNextSibling(); return null; ... |
String | getFirstElementContent(Element element, String childName) get First Element Content return element.getElementsByTagName(childName).item(0).getTextContent();
|
String | getFirstElemText(Element parent, String childName) Returns text enclosed in the first child element of the parent element Element[] childs = getChilds(parent, childName); if (childs.length == 0) { return null; return childs[0].getTextContent(); |
Element | getFirstLevelChildElementByTagName(Element parent, String elementName) Get the immediate child element with a given tag name. Node childNode = parent.getFirstChild(); while (childNode != null) { if ((childNode.getNodeType() == Node.ELEMENT_NODE) && ((Element) childNode).getLocalName().equals(elementName)) { return (Element) childNode; childNode = childNode.getNextSibling(); return null; |
Element | getFirstLevelChildElementByTagName(Element parent, String elementName) get First Level Child Element By Tag Name Node childNode = parent.getFirstChild(); while (childNode != null) { if ((childNode.getNodeType() == Node.ELEMENT_NODE) && ((Element) childNode).getLocalName().equals(elementName)) { return (Element) childNode; childNode = childNode.getNextSibling(); return null; |
List | getFirstLevelChildElements(Element parent) get First Level Child Elements NodeList nodeList = parent.getChildNodes(); ArrayList<Element> childList = new ArrayList<Element>(nodeList.getLength()); Node childNode = parent.getFirstChild(); while (childNode != null) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { childList.add((Element) childNode); childNode = childNode.getNextSibling(); ... |
List | getFirstLevelChildElements(Element parent) Get all the first level child elements. NodeList nodeList = parent.getChildNodes(); ArrayList<Element> childList = new ArrayList<Element>(nodeList.getLength()); Node childNode = parent.getFirstChild(); while (childNode != null) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { childList.add((Element) childNode); childNode = childNode.getNextSibling(); ... |