while (it.hasNext()) { Entry<String, String> entry = it.next(); xpathCompiler.declareNamespace(entry.getKey(), entry.getValue()); xpathCompiler.declareNamespace("xml",NamespaceConstant.XML); xpathCompiler.declareNamespace("xs",NamespaceConstant.SCHEMA); xpathCompiler.declareNamespace("fn",NamespaceConstant.FN);
public XPathCompiler getXPathCompiler () { XPathCompiler xpathCompiler = processor.newXPathCompiler(); xpathCompiler.declareNamespace("lux", FunCall.LUX_NAMESPACE); return xpathCompiler; }
/** * this is primarily for internal use * @return an XPathCompiler */ public XPathCompiler getXPathCompiler () { if (compiler == null) { compiler = getProcessor().newXPathCompiler(); for (Entry<String, String> nsmap : configuration.getNamespaceMap().entrySet()) { compiler.declareNamespace(nsmap.getKey(), nsmap.getValue()); } } return compiler; }
private void test(Document doc, String xpathString) throws Exception { Processor proc = new Processor(false); XdmNode docNode = proc.newDocumentBuilder().wrap(doc); XPathCompiler xpath = proc.newXPathCompiler(); xpath.declareNamespace("", "http://www.xfa.org/schema/xfa-template/2.8/"); XdmValue result = xpath.evaluate(xpathString, docNode); int fieldHits = 0; for (XdmItem item : result) { String name = ((XdmNode)node).getNodeName().getLocalName(); fieldHits = "field".equals(name) ? fieldHits + 1 : fieldHits; } System.out.println("#hits total: " + nodes.getLength()); System.out.println("#hits 'field': " + fieldHits); }
private void setNamespaces(LogicalSource logicalSource) { Object source = logicalSource.getSource(); if (source instanceof XmlSource) { ((XmlSource)source).getDeclaredNamespaces() .forEach(n -> xpath.declareNamespace(n.getPrefix(), n.getName())); } }
@Override public XPathExecutable load(ImmutablePair<String, String> key) throws Exception { String xPathQuery = key.left; String namespacesString = key.right; Processor processor = XPathUtil.getProcessor(); XPathCompiler xPathCompiler = processor.newXPathCompiler(); List<String[]> namespacesList = XPathUtil.namespacesParse(namespacesString); log.debug("Parsed namespaces:{} into list of namespaces:{}", namespacesString, namespacesList); for (String[] namespaces : namespacesList) { xPathCompiler.declareNamespace(namespaces[0], namespaces[1]); } log.debug("Declared namespaces:{}, now compiling xPathQuery:{}", namespacesList, xPathQuery); return xPathCompiler.compile(xPathQuery); } }
private void setNamespaces(LogicalSource logicalSource) { Object source = logicalSource.getSource(); if (source instanceof XmlSource) { ((XmlSource)source).getDeclaredNamespaces() .forEach(n -> xpath.declareNamespace(n.getPrefix(), n.getName())); } }
Processor proc = new Processor(); XdmNode docw = proc.newDocumentBuilder().wrap(doc); XPathCompiler xpath = proc.newXPathCompiler(); xpath.declareNamespace("ns", "http://www.example.com/XMLSchema"); XdmValue bookNodes = xpath.evaluate( "//ns:book[matches(./ns:title, '^ *XML.*?Developer.*?Guide *$', 'i')]", docw); for (XdmItem book : bookNodes) { .... }
/** * Counts all rule violations: failed asserts and successful reports). * * @param results * The validation results (svrl:schematron-output). * @return An integer value. */ private int countRuleViolations(XdmDestination results) { XPathCompiler xpath = processor.newXPathCompiler(); xpath.declareNamespace("svrl", ISO_SCHEMATRON_SVRL_NS); XdmAtomicValue totalCount = null; try { XPathExecutable exe = xpath.compile("count(//svrl:failed-assert) + count(//svrl:successful-report)"); XPathSelector selector = exe.load(); selector.setContextItem(results.getXdmNode()); totalCount = (XdmAtomicValue) selector.evaluateSingle(); } catch (SaxonApiException e) { LOGR.warning(e.getMessage()); } return Integer.parseInt(totalCount.getValue().toString()); }
XPathCompiler xPathCompiler = getXPathCompiler(); for (Map.Entry<String,String> e : indexConfig.getNamespaceMap().entrySet()) { xPathCompiler.declareNamespace(e.getKey(), e.getValue());
XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); for (String prefix : nsBindings.keySet()) { xcomp.declareNamespace(prefix, nsBindings.get(prefix));
XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); for (String prefix : nsBindings.keySet()) { xcomp.declareNamespace(prefix, nsBindings.get(prefix));
if (null != nsBindings) { for (String nsURI : nsBindings.keySet()) { compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
if (null != nsBindings) { for (String nsURI : nsBindings.keySet()) { compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
if (null != nsBindings) { for (String nsURI : nsBindings.keySet()) { compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
private XdmItem computeGroup(XdmNode node) { try { XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); xcomp.setBaseURI(step.getNode().getBaseURI()); for (String prefix : groupAdjacent.getNamespaceBindings().keySet()) { xcomp.declareNamespace(prefix, groupAdjacent.getNamespaceBindings().get(prefix)); } XPathExecutable xexec = xcomp.compile(groupAdjacent.getString()); XPathSelector selector = xexec.load(); selector.setContextItem(node); Iterator<XdmItem> values = selector.iterator(); if (values.hasNext()) { return values.next(); } else { return null; } } catch (SaxonApiException sae) { throw new XProcException(sae); } } }
private XdmItem computeGroup(XdmNode node) { try { XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); xcomp.setBaseURI(step.getNode().getBaseURI()); for (String prefix : groupAdjacent.getNamespaceBindings().keySet()) { xcomp.declareNamespace(prefix, groupAdjacent.getNamespaceBindings().get(prefix)); } XPathExecutable xexec = xcomp.compile(groupAdjacent.getString()); XPathSelector selector = xexec.load(); selector.setContextItem(node); Iterator<XdmItem> values = selector.iterator(); if (values.hasNext()) { return values.next(); } else { return null; } } catch (SaxonApiException sae) { throw new XProcException(sae); } } }
private String computedLabel(XdmNode node) throws SaxonApiException { XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); xcomp.setBaseURI(step.getNode().getBaseURI()); // Make sure any namespace bindings in-scope for the label are available for the expression for (String prefix : label.getNamespaceBindings().keySet()) { xcomp.declareNamespace(prefix, label.getNamespaceBindings().get(prefix)); } xcomp.declareVariable(p_index); XPathExecutable xexec = xcomp.compile(label.getString()); XPathSelector selector = xexec.load(); selector.setVariable(p_index,new XdmAtomicValue(count++)); selector.setContextItem(node); Iterator<XdmItem> values = selector.iterator(); XdmItem item = values.next(); return item.getStringValue(); } }
private String computedLabel(XdmNode node) throws SaxonApiException { XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); xcomp.setBaseURI(step.getNode().getBaseURI()); // Make sure any namespace bindings in-scope for the label are available for the expression for (String prefix : label.getNamespaceBindings().keySet()) { xcomp.declareNamespace(prefix, label.getNamespaceBindings().get(prefix)); } xcomp.declareVariable(p_index); XPathExecutable xexec = xcomp.compile(label.getString()); XPathSelector selector = xexec.load(); selector.setVariable(p_index,new XdmAtomicValue(count++)); selector.setContextItem(node); Iterator<XdmItem> values = selector.iterator(); XdmItem item = values.next(); return item.getStringValue(); } }
xpathCompiler.declareNamespace("", XSPEC_NAMESPACE);