List of utility methods to do XML NodeList
Element | findElement(NodeList elements, String elementName) Find an Element of a given name in a NodeList for (int i = 0; i < elements.getLength(); i++) { Node currentNode = elements.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { Element currentElement = (Element) currentNode; if (currentNode.getNodeName().equals(elementName)) { return currentElement; return null; |
LinkedList | findElementsIgnoreCase(String name, NodeList nodes) Returns a list (possibly empty) with any Elements in the list of nodes with the given name (case insensitive). LinkedList<Element> found = new LinkedList<Element>(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase(name)) { found.add((Element) n); return found; ... |
Node | findNode(NodeList nodeList, String nodeName) Search for the first Node with the nodeName().equals(nodeName) in the nodeList
Node curNode; for (int i = 0; i < nodeList.getLength(); i++) { curNode = nodeList.item(i); if (curNode.getNodeType() == Node.ELEMENT_NODE && nodeName.equals(curNode.getNodeName())) { return curNode; return null; ... |
Node | findNode(NodeList nodes, String nodeName) find Node Node result = null; for (int i = 0; i < nodes.getLength(); ++i) if (nodes.item(i).getNodeName().equals(nodeName)) result = nodes.item(i); return result; |
Node | findNode(String id, NodeList orgs) find Node Node org = null; for (int i = 0; i < orgs.getLength(); i++) { NamedNodeMap attr = orgs.item(i).getAttributes(); if (attr.getNamedItem("xml:id") == null) { continue; if (attr.getNamedItem("xml:id").getNodeValue().equals(id)) { org = orgs.item(i); ... |
Node | findNodeByName(NodeList nodeList, String name) find Node By Name Node ret = null; for (int i = 0; i < nodeList.getLength(); i++) { Node thisNode = (Node) nodeList.item(i); String nodeName = thisNode.getNodeName(); String localName = thisNode.getLocalName(); if (thisNode.getLocalName().equals(name)) { ret = thisNode; break; ... |
void | getAllNodes(NodeList nodeList, List nodes) get All Nodes int length = nodeList.getLength(); if (length == 0) { return; for (int i = 0; i < length; i++) { Node node = nodeList.item(i); nodes.add(node); getAllNodes(node.getChildNodes(), nodes); ... |
Node[] | getArray(NodeList nodeList) Returns an array version of the passed NodeList. Node[] nodes = new Node[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) nodes[i] = nodeList.item(i); return nodes; |
Node[] | getArray(NodeList nodeList) get Array Node nodes[] = new Node[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) { nodes[i] = nodeList.item(i); return nodes; |
String | getContent(NodeList nl, String path) Retrieve the text content of a specified tag if ((nl == null) || (path == null)) return null; if (nl.getLength() == 0) return null; String[] names = path.split("/"); if (names.length == 0) return null; return getContent(nl, names, 0); ... |