List of utility methods to do XML Element Find
String | findElementAsString(final Element e, final String find) Find an element, return as a string. final Element el = findElement(e, find); if (el == null) { return null; for (Node child = el.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof Text)) { continue; return child.getNodeValue(); return null; |
Element | findElementWithId(String id, Element root) fast search for Element with id attribute if (id.equals(root.getAttribute("id"))) return root; NodeList list = root.getChildNodes(); int len = list.getLength(); for (int i = 0; i < len; i++) { Node n = list.item(i); if (n.getNodeType() != Node.ELEMENT_NODE) continue; ... |
List | findNodesByType(Element topElm, int type) Finds element in DOM tree List<Node> retvals = new ArrayList<Node>(); if (topElm == null) throw new IllegalArgumentException("topElm cannot be null"); synchronized (topElm.getOwnerDocument()) { Stack<Node> stack = new Stack<Node>(); stack.push(topElm); while (!stack.isEmpty()) { Node curElm = stack.pop(); ... |
String | findNodeValue(Element firstElement, String name) find Node Value String nodeValue = null; NodeList firstNameList = firstElement.getElementsByTagName(name); Element firstNameElement = (Element) firstNameList.item(0); NodeList textFNList = firstNameElement.getChildNodes(); if (textFNList.getLength() > 0) { nodeValue = (textFNList.item(0)).getNodeValue(); return nodeValue; ... |
List | getAllElements(Element config, String elementName) returns all the element with the given name List<Element> out = new ArrayList<Element>(); 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)) { out.add(el); return out; |
NodeList | getAllElements(Element element) get All Elements return element.getElementsByTagName("*"); |
Element[] | getAllElements(Node context) get All Elements return getAllElements(context, "*"); |
List | getAllElementsByTagName(Element elem, String name) Get a list of all child text Elements of given name directly under a given org.w3c.dom.Element . NodeList nodeList = elem.getElementsByTagName(name); List<String> result = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); ++i) { NodeList children = nodeList.item(i).getChildNodes(); if (children.getLength() == 0 || children.item(0).getNodeType() != Node.TEXT_NODE) { continue; result.add(children.item(0).getNodeValue()); ... |
List | getAllLeaveValues(Element element) get All Leave Values if (element == null) { return null; List<String> ret = new LinkedList<String>(); if (isLeaf(element)) { ret.add(element.getTextContent()); } else { NodeList nl = element.getChildNodes(); ... |
String[] | getAllNodeNames(Element ele) get All Node Names NamedNodeMap atts = ele.getAttributes(); int nbrAtts = atts == null ? 0 : atts.getLength(); int nbrChildren = 0; Set<String> childNames = null; NodeList children = ele.getChildNodes(); if (children != null) { nbrChildren = children.getLength(); childNames = new HashSet<String>(); ... |