List of utility methods to do XML Element Get
Element | getElement(Element config, String elementName) returns the first element with the given name, null if none exists. NodeList children = config.getChildNodes(); for (int counter = 0; counter < children.getLength(); counter++) { if (children.item(counter) instanceof Element) { Element el = (Element) children.item(counter); if (el.getTagName().equals(elementName)) { return el; return null; |
Element | getElement(Element config, String elementName) returns the element with the given name NodeList children = config.getChildNodes(); Node node; for (int counter = 0; counter < children.getLength(); counter++) { node = children.item(counter); if (node instanceof Element) { if (((Element) node).getTagName().equals(elementName)) { return ((Element) node); return null; |
Element | getElement(Element e, String localName) get Element return getElement(e, "", localName); |
String | getElement(Element e, String name) get Element if (e.getElementsByTagName(name) == null) return ""; if (e.getElementsByTagName(name).item(0) == null) return ""; return e.getElementsByTagName(name).item(0).getTextContent(); |
Element | getElement(Element e, String nsUri, String localName) get Element NodeList l = e.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { Node n = l.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element r = (Element) n; if (equals(r.getLocalName(), localName) && equals(fixNull(r.getNamespaceURI()), nsUri)) return r; return null; |
Element | getElement(Element el, String label) get Element NodeList l = el.getElementsByTagName(label); if (l.getLength() < 1) return null; return (Element) l.item(0); |
Element | getElement(Element el, String tagName, int index) get Element NodeList list = el.getElementsByTagName(tagName);
return (Element) list.item(index);
|
Element | getElement(Element el, String... path) get Element for (int i = 0; i < path.length; i++) { el = getImmediateSubElement(el, path[i]); if (el == null) return null; return el; |
Element | getElement(Element elem, String name) get Element NodeList nl = elem.getElementsByTagName(name); if (nl.getLength() > 0) return (Element) nl.item(0); else return null; |
Element | getElement(Element elem, String path) Returns the named descendent. List elems = getElements(elem, path); if (elems.size() == 0) return null; else return (Element) elems.get(0); |