List of utility methods to do XML Child Get by Name
Element[] | getChildElements(Element element, String namespace, String localName) Returns all Element children of an Element that belong to the given namespace and have the given local name. ArrayList elements = new ArrayList(); NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) { elements.add(node); return (Element[]) elements.toArray(new Element[elements.size()]); |
List | getChildElements(Element element, String tag) get single element by tag name. return toElements(element.getChildNodes(), tag);
|
List | getChildElements(Element element, String tagName) get Child Elements List<Element> elements = getElementList(element); int numElements = elements.size(); List<Element> childElements = new ArrayList<Element>(numElements); for (int i = 0; i < numElements; i++) { Element childElement = (Element) elements.get(i); if (tagName != null) { String childTagName = childElement.getTagName(); if (!childTagName.equals(tagName)) { ... |
List | getChildElements(Element p_rootElement, String p_elementName) get Child Elements List result = new ArrayList(); NodeList nodeList = p_rootElement.getElementsByTagName(p_elementName); for (int i = 0; i < nodeList.getLength(); i++) { Element elem = (Element) nodeList.item(i); result.add(elem); return result; |
List | getChildElements(Element parent, String elementTag) Get the XML children element of an XML element, but only those of a certain type NodeList nodes = parent.getElementsByTagName(elementTag); List<Element> childElements = new ArrayList<>(); for (int i = 0; i < nodes.getLength(); i++) { Element node = (Element) nodes.item(i); if (node.getParentNode().equals(parent)) { childElements.add(node); return childElements; |
List | getChildElements(Element parent, String localName) get Child Elements List<Element> elems = new ArrayList<Element>(); NodeList nodes = parent.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(localName)) { elems.add((Element) node); return elems; |
List | getChildElements(Element parent, String name) Returns all the direct children of the parent that are Element nodes. List<Element> kids = new ArrayList<Element>(); for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if ((name.equals("*") || n.getNodeName().equals(name)) && n instanceof Element) { kids.add((Element) n); return kids; |
List | getChildElements(Element parent, String name) Gets the child elements of a parent element. List<Element> childElements = new ArrayList<Element>(); NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) childNodes.item(i); if (name == null || childElement.getLocalName().equals(name)) { childElements.add(childElement); return childElements; |
Element[] | getChildElements(Element parent, String name) get Child Elements List<Element> children = new ArrayList<Element>(); NodeList list = parent.getChildNodes(); int length = list.getLength(); for (int i = 0; i < length; ++i) { Node node = list.item(i); short type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { Element processorElement = (Element) node; ... |
Element[] | getChildElements(Element parent, String nsUri, String localPart) Gets the child elements of the given name. ArrayList a = new ArrayList(); NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node item = children.item(i); if (!(item instanceof Element)) continue; if (nsUri.equals(item.getNamespaceURI()) && localPart.equals(item.getLocalName())) a.add(item); ... |