List of utility methods to do XML Node Find
Node | findNodeByTagName(Document document, String tagName) find Node By Tag Name Node foundNode = null; NodeList nodes = document.getElementsByTagName(tagName); if (nodes.getLength() > 0) foundNode = nodes.item(0); return foundNode; |
T | findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) find Node By Xpath T userNode = null; XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile(xpathEx); org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE); if (result != null) { userNode = (T) result.getUserData(USER_KEY_NODE); return userNode; |
int | findNodeIndex(Node node) find Node Index String nm = node.getLocalName(); String ns = node.getNamespaceURI(); short nt = node.getNodeType(); Node parentNode = node.getParentNode(); if (parentNode.getNodeType() != Node.ELEMENT_NODE) { return 1; Node child = parentNode.getFirstChild(); ... |
int | findNodeIndex(Node node) find Node Index String nm = node.getLocalName(); String ns = node.getNamespaceURI(); short nt = node.getNodeType(); Node parentNode = node.getParentNode(); if (parentNode.getNodeType() != Node.ELEMENT_NODE) return 1; Node child = parentNode.getFirstChild(); int ix = 0; ... |
long | findNodeLong(Node node) find Node Long long value = 0; String text = findNodeText(node); if (text != null && !text.equals("")) value = Long.parseLong(text); return value; |
Node[] | findNodesByTagName(Document document, String tagName) find Nodes By Tag Name ArrayList<Node> nodes = new ArrayList<Node>(); NodeList foundNodes = document.getElementsByTagName(tagName); for (int i = 0; i < foundNodes.getLength(); i++) nodes.add(foundNodes.item(i)); Node[] returnNodes = new Node[nodes.size()]; return nodes.toArray(returnNodes); |
void | findNodesNamed(Node node, String lookForName, Collection find Nodes Named if (node.getNodeName().equals(lookForName)) { ret.add(node); } else { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { findNodesNamed(list.item(i), lookForName, ret); |
String | findNodeValue(Node aNode, String aName) ------------------------------------------------------------ Gets the value of the named node String value = null; Node node = findNode(aNode, aName); if (node != null) { value = getNodeValue(node); return value; |
Node | findNodeWithAttrValue(Document doc, String elementName, String attrName, String attrValue) find Node With Attr Value NodeList elmts = doc.getElementsByTagNameNS("*", elementName); ; for (int i = 0; i < elmts.getLength(); i++) { Node n = elmts.item(i); if (n == null) { continue; NamedNodeMap attrs = n.getAttributes(); ... |