List of utility methods to do XML Element Child Get
Element | findChild(Element parent, String tagName) Returns the child element with the specified tagName for the specified parent element. if (parent == null || tagName == null) throw new NullPointerException("Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { node = nodes.item(i); ... |
Element | findChildElement(Element parent, String name) find Child Element if (parent == null) { return null; org.w3c.dom.Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals( name))) { ret = ret.getNextSibling(); ... |
Element | findChildElementWithAttribute(Element parent, String name, String attribute, String value) find Child Element With Attribute if (parent == null) { return null; org.w3c.dom.Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name) || ((Element) ret).getAttribute(attribute) == null || !((Element) ret) ... |
List | findChildren(Element parent, String tagName) Returns the children elements with the specified tagName for the specified parent element. if (parent == null || tagName == null) throw new NullPointerException("Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); List<Element> result = new ArrayList<Element>(); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { ... |
Element | findFirstChildElement(Element parent) find First Child Element org.w3c.dom.Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element))) { ret = ret.getNextSibling(); return (Element) ret; |
Element | firstChildWithName(Element element, String name) first Child With Name NodeList list = element.getChildNodes(); final int length = list.getLength(); for (int i = 0; i < length; ++i) { Node n = list.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) return (Element) n; return null; |
Element | getChild(Element element, String name) Get the first child element with the given name. return (Element) element.getElementsByTagName(name).item(0);
|
Node | getChildByType(Element element, short nodeType) Returns first of the element's child nodes that is of type nodeType. if (element == null) return null; NodeList nodes = element.getChildNodes(); if (nodes == null || nodes.getLength() < 1) return null; Node node; String data; for (int i = 0; i < nodes.getLength(); i++) { ... |
Element | getChildElementByName(Element parent, String name) get Child Element By Name List<Element> children = getChildElementsByName(parent, name); if (children.size() == 0) { return null; if (children.size() > 1) { throw new RuntimeException("Unexpected number of '" + name + "' elements " + children.size()); return children.get(0); |
String | getChildValue(Element element, String name) Get the value of the fist child element with the given name. return getValue(getChild(element, name));
|