List of utility methods to do XML Node Search
Node | findNamedElementNode(Node doc, String name) find Named Element Node Node[] elnodes = getChildNodes(doc, Node.ELEMENT_NODE); int i; for (i = 0; i < elnodes.length; ++i) { if (elnodes[i].getNodeName().equals(name)) return elnodes[i]; return null; |
List | findNamedElementNodes(Node doc, String name) find Named Element Nodes Node[] elnodes = getChildNodes(doc, Node.ELEMENT_NODE); List<Node> nodes = new ArrayList<Node>(); int i; for (i = 0; i < elnodes.length; ++i) { if (elnodes[i].getNodeName().equals(name)) { nodes.add(elnodes[i]); return nodes; |
Element | findNextElement(Node ret, String name) find Next Element ret = ret.getNextSibling(); while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals( name))) { ret = ret.getNextSibling(); return (Element) ret; |
String | getOptionalXmlString(Node node, String xmlLocalName) Retrieves the value of that XML element as a string. Node child = getFirstChild(node, xmlLocalName);
return child == null ? null : child.getTextContent();
|
String | returnNodeValue(Node node) Returns the value of an XML node. String text = node.getFirstChild().getTextContent(); text = text.replaceAll("\\\\n", "\n"); return text; |
Element | selectNode(Node sibling, String uri, String nodeName, int number) select Node while (sibling != null) { if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri) && sibling.getLocalName().equals(nodeName)) { if (number == 0) { return (Element) sibling; number--; ... |
Text | selectNodeText(Node sibling, String uri, String nodeName, int number) select Node Text Node n = selectNode(sibling, uri, nodeName, number); if (n == null) { return null; n = n.getFirstChild(); while (n != null && n.getNodeType() != Node.TEXT_NODE) { n = n.getNextSibling(); return (Text) n; |
Element[] | selectNodes(Node sibling, String uri, String nodeName) select Nodes List<Element> list = new ArrayList<Element>(); while (sibling != null) { if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri) && sibling.getLocalName().equals(nodeName)) { list.add((Element) sibling); sibling = sibling.getNextSibling(); ... |