List of utility methods to do XPath Get
Element | getElementByXpath(Element sourceRoot, String xpathExpress) get Element By Xpath XPath xPath = XPATH_FACTORY.newXPath(); NodeList nodes = (NodeList) xPath.evaluate(xpathExpress, sourceRoot, XPathConstants.NODESET); if (nodes.getLength() > 0) return (Element) nodes.item(0); return null; |
List | getElementsByXPath(Element parent, String name) get Elements By X Path List<Element> result = new ArrayList<>(); for (Node node : getNodesByXPath(parent, name)) { if (node instanceof Element) { result.add((Element) node); return result; |
String | getElementXPath(Node elt) Resolves the xpath of an element. String path = ""; Node currentNode = elt; while (!(currentNode instanceof Document)) { Element parent = (Element) currentNode; if (!parent.getTagName().equals("schema")) { if (!parentNodeHasMoreOfThese((Element) currentNode)) { path = '/' + parent.getTagName() + path; } else { ... |
String | getExcelPath() get Excel Path HashMap<String, String> configs = getConfigurations(); String path = configs.get("excel-path"); return path; |
XPathFactory | getFactory() get Factory if (factory == null) { factory = createFactory(); return factory; |
String | getFastXPath(Node node) Returns a valid FastXPath that would match the given Node in its Document. StringBuffer buf = new StringBuffer(); Element ele; switch (node.getNodeType()) { case Node.ELEMENT_NODE: ele = (Element) node; break; case Node.ATTRIBUTE_NODE: buf.append("/@"); ... |
Node | getFirstByXPath(Object obj, String xpathExpression) Get the first node from the specified object using the specified XPath expression. return evaluate(obj, xpathExpression, XPathConstants.NODE);
|
String | getFullXPath(Node n) get Full X Path if (null == n) return null; Node parent = null; Stack<Node> hierarchy = new Stack<Node>(); StringBuffer buffer = new StringBuffer(); hierarchy.push(n); switch (n.getNodeType()) { case Node.ATTRIBUTE_NODE: ... |
XPath | getHtmlXPath() get Html X Path XPathFactory factory = XPathFactory.newInstance(); XPath htmlPath = factory.newXPath(); htmlPath.setNamespaceContext(new NamespaceContext() { public String getNamespaceURI(String prefix) { return "http://www.w3.org/1999/xhtml"; public String getPrefix(String namespaceURI) { return "h"; ... |
int | getInt(Object node, XPathExpression expression) get Int return ((Double) expression.evaluate(node, XPathConstants.NUMBER)).intValue();
|