List of utility methods to do XML Child Get by Name
Element | getChildElement(Element ele, String childName) Utility method that returns the first child element identified by its getName. NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameEquals(node, childName)) return (Element) node; return null; |
Element | getChildElement(Element elem, String name) get Child Element NodeList nodes = elem.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) { return (Element) node; return null; ... |
Element | getChildElement(Element element, String childName) get Child Element for (org.w3c.dom.Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE && ((Element) node).getTagName().equals(childName)) { return (Element) node; return null; |
Element | getChildElement(Element element, String elementName) Returns the first child element with the specified name, or null if none exists. for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Element) { Element childElem = (Element) node; String elemName = getElementName(childElem); if (elementName.equals(elemName)) return childElem; return null; |
Element | getChildElement(Element element, String name) Returns the child element with the specified name for the specified element. NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element childElement = (Element) node; if (childElement.getNodeName().equals(name)) { return childElement; return null; |
Element | GetChildElement(Element element, String name) Get Child Element if (element != null && name != null && !name.isEmpty()) { NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element && name.equals(node.getNodeName())) { return (Element) node; return null; |
Element | getChildElement(Element element, String tagName) Returns a child element with a given name from an XML element if (element == null) return null; NodeList list = element.getElementsByTagName(tagName); if (list != null && list.getLength() > 0) { return (Element) list.item(0); return null; |
Element | getChildElement(Element element, String tagName) get Child Element NodeList childNodes = element.getChildNodes(); int numChildren = childNodes.getLength(); for (int i = 0; i < numChildren; i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() != Node.ELEMENT_NODE) { continue; Element childElement = (Element) childNode; ... |
Element | getChildElement(Element parent, String childName) get Child Element NodeList children = parent.getChildNodes(); int size = children.getLength(); for (int i = 0; i < size; i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (childName.equals(element.getNodeName())) { return element; ... |
Element | getChildElement(Element parent, String childName) get Child Element NodeList list = parent.getElementsByTagName(childName); Node node; for (int i = 0; i < list.getLength(); i++) { node = list.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { return (Element) node; return null; |