List of utility methods to do XML Element Get by Name
List | getElementsByTagNameCaseInsensitive(Document doc, final Set get Elements By Tag Name Case Insensitive final List<Element> result = Lists.newArrayList(); NodeIterator nodeIterator = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NodeFilter() { public short acceptNode(Node n) { if (lowerCaseNames.contains(n.getNodeName().toLowerCase())) { return NodeFilter.FILTER_ACCEPT; return NodeFilter.FILTER_REJECT; ... |
String | getElementValue(Element parent) get Element Value NodeList nodes = parent.getChildNodes(); int current = 0; int length = nodes.getLength(); while (current < length) { Node node = nodes.item(current); if (node instanceof Text) { String value = node.getNodeValue(); if (value != null) { ... |
String | getElementValue(Element parent, String tagName) Gets the value of the child element by tag name under the given parent element. String value = null; Element element = getElement(parent, tagName); if (element != null) { value = element.getTextContent(); return value; |
String | getElementValue(Element parent, String tagName) get Element Value Element element = getChildElement(parent, tagName); if (element != null) { NodeList nodes = element.getChildNodes(); if ((nodes != null) && (nodes.getLength() > 0)) { for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if ((node instanceof Text)) { return ((Text) node).getData(); ... |
Element | getFirstElement(Element parent, String name) get the first element in the parent element that's named name or null if no such element exists NodeList list = parent.getElementsByTagName(name); Node node = list.item(0); if (node == null) { return null; if (!isElement(node)) { throw new RuntimeException("XML Parsing error: " + name + " is not an Element"); return (Element) node; |
Element | getFirstElementAtAnyDepthByNodeName(Element parent, String name) Find the first element that is a child or subchild under a given Element parent. NodeList l = parent.getChildNodes(); int count = l.getLength(); for (int i = 0; i < count; i++) { Node n = l.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; String nodeName = e.getNodeName(); if (name.equals(nodeName)) { ... |
Element | getFirstElementByName(Element parent, String name) Find a element by name. NodeList l = parent.getChildNodes(); int count = l.getLength(); for (int i = 0; i < count; i++) { Node n = l.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; String localName = e.getLocalName(); if (localName == null) { ... |
Element | getFirstElementByName(String name, Element parent) get First Element By Name return (Element) parent.getElementsByTagName(name).item(0);
|
Element | getFirstElementByTagName(Element parent, String tagName) get First Element By Tag Name List<Element> foundElements = getNamedChildElements(parent, tagName); if (foundElements.size() > 0) { return foundElements.get(0); } else { return null; |
Element | getGrandSonElementByTagName(Element element, String parentName, String eleName) get Grand Son Element By Tag Name NodeList nl = element.getElementsByTagName(parentName); if (null == nl) { return null; Node item = nl.item(0); return getChildElementByTagName((Element) item, eleName); |