List of utility methods to do XML Element Get by Attribute
List | findAllElementsByAttribute(Node node, String tagName, String attrName, String attrValue) Reqursion search in node for elements with paramantrs List<Element> result = new LinkedList<Element>(); findAllElementsByAttribute(node, tagName, attrName, attrValue, result); return result; |
List | findAllElementsByAttributes(Element node, String tagName, String attrName, List find All Elements By Attributes List<Element> result = new ArrayList<Element>(); findAllElementsByAttributes(node, tagName, attrName, attrValues, result); return result; |
Element | findComponent(Element element, String attributeValue) If there is no such Element object one will be created on element . return findElement(element, "component", attributeValue); |
Element | findElement(Element element, String elementName, String attributeValue) If there is no such element, one will be created on element . NodeList children = element.getElementsByTagName(elementName); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (!(child instanceof Element)) { continue; Element childElement = (Element) child; if (childElement.hasAttribute("name") && attributeValue.equals(childElement.getAttribute("name"))) { ... |
Element | findElement(Element parent, String elementNS, String elementName, String attrName, String attrValue) find Element NodeList l = parent.getElementsByTagNameNS(elementNS, elementName); for (int i = 0; i < l.getLength(); i++) { Element e = (Element) l.item(i); String val = e.getAttribute(attrName); if (val != null && val.equals(attrValue)) { return e; return null; |
Element | findElementByAttribute(final NodeList list, final String name, final String value) find Element By Attribute for (int i = 0; i < list.getLength(); ++i) { if (list.item(i).getNodeType() == Node.ELEMENT_NODE) { final Element e = (Element) list.item(i); if (e.hasAttribute(name) && e.getAttribute(name).equals(value)) { return e; return null; |
List | findElementsByAttribute(Element node, String tagName, String attrName, List find Elements By Attribute List<Element> result = new LinkedList<Element>(); NodeList nodeList = node.getChildNodes(); if (nodeList == null) { return result; for (int i = 0; i < nodeList.getLength(); ++i) { Element element = checkIfElement(nodeList.item(i), tagName); if (element != null) { ... |
Element | findElementWithAttributes(Node node, String tagName, Collection find Element With Attributes Element result = null; NodeList nodeList = node.getChildNodes(); if (nodeList == null) { return result; for (int i = 0; i < nodeList.getLength(); ++i) { Element element = checkIfElement(nodeList.item(i), tagName); if (element != null) { ... |
Element | findElementWithNameAttribute(Element parent, String name) Trys to find a child element in the given parent element where the child's name attribute is the given value. NodeList l = parent.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { Node n = l.item(i); if (n.getNodeType() == n.ELEMENT_NODE) { Element e = (Element) n; if (e.getAttribute("name").equals(name)) { return e; return null; |
Element | findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue) find Element With Unique Attribute NodeList list = root.getElementsByTagName(elementName); for (int i = 0; i < list.getLength(); i++) { Element tmp = (Element) list.item(i); if (tmp.getAttribute(attribute).equals(attributeValue)) { return tmp; return null; ... |