@SuppressWarnings( "unchecked" ) private boolean applyXPath() { try { XPath xpath = data.document.createXPath( data.PathValue ); if ( meta.isNamespaceAware() ) { xpath = data.document.createXPath( addNSPrefix( data.PathValue, data.PathValue ) ); xpath.setNamespaceURIs( data.NAMESPACE ); } // get nodes list data.an = xpath.selectNodes( data.document ); data.nodesize = data.an.size(); data.nodenr = 0; } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "GetXMLData.Log.ErrorApplyXPath", e.getMessage() ) ); return false; } return true; }
XPath xExclude = dom.createXPath(exclude); xExclude.setFunctionContext(functionContext); List<org.dom4j.Node> list = (List<org.dom4j.Node>)xExclude.selectNodes(dom); result = dom; } else { XPath comp = dom.createXPath(xpath); comp.setFunctionContext(functionContext); List list = comp.selectNodes(dom);
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
private XPath createXPath( String xpathExpr ) { XPath xpath = document.createXPath( xpathExpr ); if ( !this.namespaceMap.isEmpty() ) { xpath.setNamespaceURIs( this.namespaceMap ); } return xpath; }
public XPath createXPath(String xpathExpression) throws InvalidXPathException { return getWrapped().createXPath(xpathExpression); }
private List<Node> findNodesMatchingInDoc(Document pomXml, String xpath) { XPath xpathForPluginManagement = pomXml.createXPath(xpath); xpathForPluginManagement.setNamespaceURIs(namespaceUris); return xpathForPluginManagement.selectNodes(pomXml); }
@Override public boolean matches(Object o) { if (o instanceof String) { String input = (String) o; try { Document document = DocumentHelper.parseText(input); XPath xPath = document.createXPath(this.expression); if (this.contexts != null) { xPath.setNamespaceURIs(this.contexts.build()); } List<Node> list = xPath.selectNodes(document); boolean contains = !list.isEmpty(); return contains; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } return false; }
private ImmutableMap<String, PageProperty> extractDetails(String macroBodyXhtml) throws IOException, DocumentException, ParserConfigurationException, SAXException { final Document macroBodyDoc = getMacroBodyDocument(macroBodyXhtml); final XPath xpath = macroBodyDoc.createXPath(XPATH_TBODY); xpath.setNamespaceURIs(NAMESPACE_MAP); final ImmutableMap<String, PageProperty> emptyMap = ImmutableMap.of(); final Element tableElement = (Element) xpath.selectSingleNode(macroBodyDoc); if (tableElement == null) return emptyMap; @SuppressWarnings("unchecked") final List<Element> rowElements = tableElement.elements("tr"); if (rowElements == null) return emptyMap; return loadDetailPairsFromTableRows(rowElements); }
@Override public boolean matches(Object o) { if (o instanceof String) { String input = (String) o; try { Document document = DocumentHelper.parseText(input); XPath xPath = document.createXPath(this.expression); if (this.namespaces != null) xPath.setNamespaceURIs(this.namespaces.build()); String evaluatedValue = xPath.valueOf(document); return !xPath.selectNodes(document).isEmpty() && value.matches(evaluatedValue); } catch (DocumentException e) { throw new RuntimeException(e.getMessage(), e); } } System.err.println("Incorrect input"); return false; }
namespaceMap.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); namespaceMap.put("dc", "http://purl.org/dc/elements/1.1/"); XPath xpath = document.createXPath("//rdf:Description"); xpath.setNamespaceURIs(namespaceMap); Node node = xpath.selectSingleNode(lexicon);
public void testURIMap() throws Exception { Map<String, String> uris = new HashMap<String, String>(); uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"); uris.put("m", "urn:xmethodsBabelFish"); String path = "/SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish"; XPath xpath = document.createXPath(path); xpath.setNamespaceURIs(uris); Node babelfish = xpath.selectSingleNode(document); // log( "Found: " + babelfish ); assertNotNull("Found valid node", babelfish); }
XPath xExclude = dom.createXPath(exclude); xExclude.setFunctionContext(functionContext); List<org.dom4j.Node> list = (List<org.dom4j.Node>)xExclude.selectNodes(dom); result = dom; } else { XPath comp = dom.createXPath(xpath); comp.setFunctionContext(functionContext); List list = comp.selectNodes(dom);
XPath xpath = doc.createXPath(expression); if (namespaces != null)
protected void testBadPath(String path) throws Exception { try { document.selectObject(path); fail("Should have thrown exception for: " + path); } catch (Exception e) { log("Successfully caught: " + e); } try { XPath xpath = document.createXPath(path); fail("Should have thrown exception for: " + path); } catch (Exception e) { log("Successfully caught: " + e); } } }
System.out.println(top.asXML()); XPath test1 = top.createXPath("/root/child1/child11"); XPath test2 = top.createXPath("/root/child2/child21"); Node position1 = test1.selectSingleNode(root); Node position2 = test2.selectSingleNode(root);