String value = formatItem(item, context); String attributeName = entry.getKey(); if (result.size() > 1) { attributeName += "." + index++; if (result.size() == 0) { logger.info("Routing {} to 'unmatched'", new Object[]{flowFile}); session.transfer(flowFile, REL_NO_MATCH); continue flowFileLoop; } else if (result.size() == 1) { final XdmItem item = result.itemAt(0); flowFile = session.write(flowFile, new OutputStreamCallback() {
public int size() { return value.size(); }
Processor proc = new Processor(); InputStream input = new FileInputStream("/tmp/g.html"); XMLReader reader = new Parser(); reader.setFeature(Parser.namespacesFeature, false); Source source = new SAXSource(parser, input); DocumentBuilder builder = proc.newDocumentBuilder(); XdmNode input = builder.build(source); XPathCompiler compiler = proc.newXPathCompiler(); XdmValue result = compiler.evaluate("//span", input); System.out.println(result.size());
/** * Run the tests to assess "Atom WMS" conformance only if the context * document contains WMS service offerings. Otherwise they will be skipped. */ @BeforeTest public void hasWmsOfferings() { String xpath = String.format("//owc:offering[@code='%s']", OWC10.ATOM_WMS_OFFERING); Source source = new StreamSource(this.contextFile); XdmValue result; try { result = XMLUtils.evaluateXPath2(source, xpath, Collections.singletonMap(Namespaces.OWC, "owc")); } catch (SaxonApiException e) { throw new AssertionError(e.getMessage()); } if (result.size() == 0) { throw new SkipException("No WMS offerings found."); } }
/** * Get the n'th item in the value, counting from zero. * * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException("" + n); } try { Item<?> item = SequenceTool.itemAt(value, n); return (XdmItem)XdmItem.wrap(item); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
XdmValue result = XMLUtils.evaluateXPath2( new DOMSource(record), expr, null); Assert.assertTrue(result.size() > 0, ErrorMessage.format(ErrorMessageKeys.XPATH_RESULT, Records.getRecordId(record), new Object[]{Records.getRecordId(record), result.size(), term, XMLUtils.writeXdmValueToString(result)}); } catch (SaxonApiException sae) {
/** * Get the n'th item in the value, counting from zero. * * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException("" + n); } try { Item<?> item = SequenceTool.itemAt(value, n); return (XdmItem)XdmItem.wrap(item); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
/** * Get the n'th item in the value, counting from zero. * @param n the item that is required, counting the first item in the sequence as item zero * @return the n'th item in the sequence making up the value, counting from zero * @throws IndexOutOfBoundsException if n is less than zero or greater than or equal to the number * of items in the value * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public XdmItem itemAt(int n) throws IndexOutOfBoundsException, SaxonApiUncheckedException { if (n < 0 || n >= size()) { throw new IndexOutOfBoundsException(""+n); } if (value instanceof Value) { try { return (XdmItem)XdmItem.wrap(((Value)value).itemAt(n)); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } } else { return (XdmNode)XdmNode.wrap((NodeInfo)value); } }
/** * Asserts that an XPath 2.0 expression evaluates to {@code true} for the * given XML source. That is, the result set is not empty. * * @param expr * An XPath 2.0 expression. * @param source * A Source object representing an XML resource. * @param namespaceBindings * A collection of namespace bindings for the XPath expression, * where each entry maps a namespace URI (key) to a prefix * (value). It may be {@code null}. */ public static void assertXPath2(String expr, Source source, Map<String, String> namespaceBindings) { XdmValue result = null; try { result = XMLUtils.evaluateXPath2(source, expr, namespaceBindings); } catch (SaxonApiException e) { throw new AssertionError(ErrorMessage.format( ErrorMessageKeys.XPATH_ERROR, expr + e.getMessage())); } Assert.assertTrue( result.size() > 0, ErrorMessage.format(ErrorMessageKeys.XPATH_RESULT, source.getSystemId(), expr)); }
XdmValue result = XMLUtils.evaluateXPath2(uomSource, xpath, Collections.singletonMap(UCUM_NS, "ucum")); if (result.size() == 0) { errHandler .addError(
"Failed to evaluate XPath expression", sae); if (null == result || result.size() == 0) { errHandler.addError( ErrorSeverity.ERROR,
try { xdmValue = XMLUtils.evaluateXPath2(source, xpath, nsMap); if (xdmValue.size() == 0) { xpath = String.format( "//ows:Constraint[ends-with(@name,'%s')]//ows:Value[1]", if (xdmValue.size() == 0 || !xdmValue.itemAt(0).getStringValue().trim().equalsIgnoreCase("TRUE")) { throw new AssertionError("OpenSearch not a supported capability.");
selector.setContextItem(xdmNode); XdmValue nodes = selector.evaluate(); int length = nodes.size(); int indexToMatch = matchNumber;
String value = formatItem(item, context); String attributeName = entry.getKey(); if (result.size() > 1) { attributeName += "." + index++; if (result.size() == 0) { logger.info("Routing {} to 'unmatched'", new Object[]{flowFile}); session.transfer(flowFile, REL_NO_MATCH); continue flowFileLoop; } else if (result.size() == 1) { final XdmItem item = result.itemAt(0); flowFile = session.write(flowFile, new OutputStreamCallback() {