List of utility methods to do XML Element Get by Name
Element | getElementByTagName(Document doc, String eleName) get Element By Tag Name NodeList nl = doc.getElementsByTagName(eleName); if (null == nl) { return null; Node item = nl.item(0); return (Element) item; |
Node | getElementByTagName(Document document, String tagName) get Element By Tag Name if (document == null || tagName == null) { return null; NodeList nodes = document.getElementsByTagName(tagName); if (nodes == null || nodes.getLength() < 1) { return null; return nodes.item(0); ... |
Element | getElementByTagName(Element aParent, String aName) get Element By Tag Name Node child = aParent.getFirstChild(); while (child != null) { if (child instanceof Element && ((Element) child).getTagName().equals(aName)) { return (Element) child; child = child.getNextSibling(); return null; ... |
Element | getElementByTagName(Element parent, String elementName) get Element By Tag Name NodeList nodeList = parent.getElementsByTagName(elementName); if (nodeList.getLength() > 0) { return (Element) nodeList.item(0); return null; |
Element | getElementByTagName(Element parent, String elementName) Get a child element with a given tag name. NodeList nodeList = parent.getElementsByTagName(elementName); if (nodeList.getLength() > 0) { return (Element) nodeList.item(0); return null; |
Element | getElementByTagNameWithParents(Element n, String... elementName) Gets the first child Element with a given name for (String elName : elementName) { Element subEl = getElementByTagName(n, elName); if (subEl == null) return null; n = subEl; return n; |
Date | getElementDateValue(Document document, Element parent, String string) get Element Date Value return parseDate(getElementStringValue(document, parent, string));
|
float | getElementFloatValue(Document document, Element parent, String element) get Element Float Value return Float.parseFloat(getElementStringValue(document, parent, element));
|
List | getElements(Element parent, String localName) get Elements List<Element> result = new ArrayList<Element>(); Node child = parent.getFirstChild(); while (child != null) { if (child instanceof Element && child.getLocalName().equals(localName)) { result.add((Element) child); child = child.getNextSibling(); return result; |
List | getElements(Element parent, String localname, String namespaceURI) Get the child elements having the supplied localname and namespace. return getElements(parent.getChildNodes(), localname, namespaceURI);
|