Refine search
private static XPathExpression compileXpathExpression(String expression, @Nullable Map<String, String> namespaces) throws XPathExpressionException { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces != null ? namespaces : Collections.emptyMap()); XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(namespaceContext); return xpath.compile(expression); }
private XPath newXPath() { XPath xpath = xPathFactory.newXPath(); xpath.setNamespaceContext(namespaceContext); xpath.setXPathVariableResolver(variableResolver); return xpath; }
private static XPathExpression compiledXPath(String xPathExpression, NamespaceContext namespaceContext) { try { final XPath xPath = XPathFactory.newInstance().newXPath(); if (namespaceContext != null) { xPath.setNamespaceContext(namespaceContext); } return xPath.compile(xPathExpression); } catch (XPathExpressionException e) { throw new IllegalArgumentException("Invalid XPath : " + xPathExpression, e); } }
public static NodeList evalXPath( Node node, NamespaceContext nsContext, String query) throws XPathFactoryConfigurationException, XPathExpressionException { XPath xPath = getSaxonXPathFactory().newXPath(); xPath.setNamespaceContext(nsContext); NodeList nodes = (NodeList) xPath.evaluate(query, node, XPathConstants.NODESET); return nodes; }
public static NodeList query(Node node, String searchString, XPathContext xpathcontext) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(xpathcontext); return (NodeList) xpath.evaluate(searchString, node, XPathConstants.NODESET); }
private synchronized XPath createXPath() { XPath xpath = xpathFactory.newXPath(); if (namespaces != null) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); } return xpath; }
private static XPathExpression compiledXPath(String xPathExpression, NamespaceContext namespaceContext) { try { final XPath xPath = XPathFactory.newInstance().newXPath(); if (namespaceContext != null) { xPath.setNamespaceContext(namespaceContext); } return xPath.compile(xPathExpression); } catch (XPathExpressionException e) { throw new IllegalArgumentException("Invalid XPath : " + xPathExpression, e); } }
private XPath createXPath () { XPath xpath = xpFact.newXPath(); NSContextManager nsc = new NSContextManager(); nsc.addNamespace(Namespaces.ITS_NS_PREFIX, Namespaces.ITS_NS_URI); nsc.addNamespace(Namespaces.HTML_NS_PREFIX, Namespaces.HTML_NS_URI); nsc.addNamespace(Namespaces.XML_NS_PREFIX, Namespaces.XML_NS_URI); xpath.setNamespaceContext(nsc); return xpath; }
public static Element querySingleElement(Node node, String searchString, final XPathContext xPathContext) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(xPathContext); Object result = xpath.evaluate(searchString, node, XPathConstants.NODE); try { return (Element) result; } catch (ClassCastException e) { throw new XPathExpressionException("Not an org.w3c.dom.Element: " + result); } }
/** Constructor is protected, use the static Singleton instance */ protected XMLXpathFactory() { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(urContext); urExpression = compile(xpath, "/" + NSP_UR + ":" + E_USERREGISTRY_UR + "/@" + A_VERSION_UR); xpath.setNamespaceContext(rrContext); rrExpression = compile(xpath, "/" + NSP_RR + ":" + E_ROLEREGISTRY_RR + "/@" + A_VERSION_RR); }
private XPathExpression makeXPathExpression(String xpathStr) throws XPathExpressionException { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(new EDCNamespaceContext()); XPathExpression expr = xpath.compile(xpathStr); return expr; }
private static long latestTimestamp(Document document) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); xpath.setNamespaceContext(TtmlHelpers.NAMESPACE_CONTEXT); try { XPathExpression xp = xpath.compile("//*[name()='p']"); NodeList timedNodes = (NodeList) xp.evaluate(document, XPathConstants.NODESET); long lastTimeStamp = 0; for (int i = 0; i < timedNodes.getLength(); i++) { lastTimeStamp = Math.max(getEndTime(timedNodes.item(i)), lastTimeStamp); } return lastTimeStamp; } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
protected long lastTimestamp(Document document) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); xpath.setNamespaceContext(TtmlHelpers.NAMESPACE_CONTEXT); try { XPathExpression xp = xpath.compile("//*[@end]"); NodeList timedNodes = (NodeList) xp.evaluate(document, XPathConstants.NODESET); long lastTimeStamp = 0; for (int i = 0; i < timedNodes.getLength(); i++) { lastTimeStamp = Math.max(getEndTime(timedNodes.item(i)), lastTimeStamp); } return lastTimeStamp; } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
protected long firstTimestamp(Document document) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); xpath.setNamespaceContext(TtmlHelpers.NAMESPACE_CONTEXT); try { XPathExpression xp = xpath.compile("//*[@begin]"); NodeList timedNodes = (NodeList) xp.evaluate(document, XPathConstants.NODESET); long firstTimestamp = Long.MAX_VALUE; for (int i = 0; i < timedNodes.getLength(); i++) { firstTimestamp = Math.min(getStartTime(timedNodes.item(i)), firstTimestamp); } return firstTimestamp; } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); HashMap<String, String> prefMap = new HashMap<String, String>() {{ put("main", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); put("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); }}; SimpleNamespaceContext namespaces = new SimpleNamespaceContext(prefMap); xpath.setNamespaceContext(namespaces); XPathExpression expr = xpath .compile("/main:workbook/main:sheets/main:sheet[1]"); Object result = expr.evaluate(doc, XPathConstants.NODESET);
// load the Document Document document = ...; NamespaceContext ctx = new NamespaceContext() { public String getNamespaceURI(String prefix) { return prefix.equals("urn") ? "urn:camera-org" : null; } public Iterator getPrefixes(String val) { return null; } public String getPrefix(String uri) { return null; } }; XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(ctx); String responseStatus = xpath.evaluate("//urn:ResponseStatus/text()", document); System.out.println("-> " + responseStatus);
public static Document normalizeTimes(Document doc) throws XPathExpressionException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); xpath.setNamespaceContext(TtmlHelpers.NAMESPACE_CONTEXT); XPathExpression xp = xpath.compile("//*[name()='p']"); NodeList timedNodes = (NodeList) xp.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < timedNodes.getLength(); i++) { Node p = timedNodes.item(i); pushDown(p); } for (int i = 0; i < timedNodes.getLength(); i++) { Node p = timedNodes.item(i); removeAfterPushDown(p, "begin"); removeAfterPushDown(p, "end"); } return doc; }
xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(nsContext);
xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(nsContext);
Document dDoc = builder.parse("E:/test.xml"); XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); NodeList nl = (NodeList) xPath.evaluate("/ns:root/ns:author", dDoc, XPathConstants.NODESET); System.out.println(nl.getLength());