当前位置: 首页>>代码示例>>Java>>正文


Java Processor.newXPathCompiler方法代码示例

本文整理汇总了Java中net.sf.saxon.s9api.Processor.newXPathCompiler方法的典型用法代码示例。如果您正苦于以下问题:Java Processor.newXPathCompiler方法的具体用法?Java Processor.newXPathCompiler怎么用?Java Processor.newXPathCompiler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.saxon.s9api.Processor的用法示例。


在下文中一共展示了Processor.newXPathCompiler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyXpath

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
public static List<String> applyXpath(String xml, String xpathString) {
  List<String> result = new ArrayList<>();
  try {
    Processor proc = new Processor(false);
    XPathCompiler xpath = proc.newXPathCompiler();
    DocumentBuilder builder = proc.newDocumentBuilder();

    // Load the XML document.
    StringReader reader = new StringReader(xml);
    XdmNode doc = builder.build(new StreamSource(reader));

    // Compile the xpath
    XPathSelector selector = xpath.compile(xpathString).load();
    selector.setContextItem(doc);

    // Evaluate the expression.
    XdmValue nodes = selector.evaluate();

    for (XdmItem item : nodes) {
      result.add(item.toString());
    }

  } catch (Exception e) {
    LOGGER.error("Error applying XPath", e);
  }
  return result;
}
 
开发者ID:keeps,项目名称:roda-in,代码行数:28,代码来源:TemplateUtils.java

示例2: evaluateXPath2

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
 * Evaluates an XPath 2.0 expression using the Saxon s9api interfaces.
 *
 * @param xmlSource
 *            The XML Source.
 * @param expr
 *            The XPath expression to be evaluated.
 * @param nsBindings
 *            A collection of namespace bindings required to evaluate the
 *            XPath expression, where each entry maps a namespace URI (key)
 *            to a prefix (value).
 * @return An XdmValue object representing a value in the XDM data model;
 *         this is a sequence of zero or more items, where each item is
 *         either an atomic value or a node.
 * @throws SaxonApiException
 *             If an error occurs while evaluating the expression; this
 *             always wraps some other underlying exception.
 */
public static XdmValue evaluateXPath2(Source xmlSource, String expr,
        Map<String, String> nsBindings) throws SaxonApiException {
    Processor proc = new Processor(false);
    XPathCompiler compiler = proc.newXPathCompiler();
    for (String nsURI : nsBindings.keySet()) {
        compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
    }
    XPathSelector xpath = compiler.compile(expr).load();
    DocumentBuilder builder = proc.newDocumentBuilder();
    XdmNode node = null;
    if (DOMSource.class.isInstance(xmlSource)) {
        DOMSource domSource = (DOMSource) xmlSource;
        node = builder.wrap(domSource.getNode());
    } else {
        node = builder.build(xmlSource);
    }
    xpath.setContextItem(node);
    return xpath.evaluate();
}
 
开发者ID:opengeospatial,项目名称:ets-osxgeotime10,代码行数:38,代码来源:XMLUtils.java

示例3: constructElementParserDatatype

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
private Datatype constructElementParserDatatype(final QName qn, final boolean allowsEmpty, final boolean allowsMultiple) throws ValidationException {
    return new Datatype() {
        @Override
        public boolean isAtomic() { return false; }
        @Override
        public boolean allowsMultiple() { return allowsMultiple; }
        @Override
        public boolean allowsEmpty() { return allowsEmpty; }
        @Override
        public XdmValue convert(String input, Configuration configuration) throws ValidationException {
            Processor proc = new Processor(configuration);
            DocumentBuilder builder = proc.newDocumentBuilder();
            String wrappedInput="<fake:document xmlns:fake=\"top:marchand:xml:gaulois:wrapper\">".concat(input).concat("</fake:document>");
            InputStream is = new ByteArrayInputStream(wrappedInput.getBytes(Charset.forName("UTF-8")));
            try {
                XdmNode documentNode = builder.build(new StreamSource(is));
                XPathCompiler compiler = proc.newXPathCompiler();
                compiler.declareNamespace("fake", "top:marchand:xml:gaulois:wrapper");
                XPathSelector selector = compiler.compile("/fake:document/node()").load();
                selector.setContextItem(documentNode);
                XdmValue ret = selector.evaluate();
                if(ret.size()==0 && !allowsEmpty()) throw new ValidationException(qn.toString()+" does not allow empty sequence");
                if(ret.size()>1 && !allowsMultiple()) throw new ValidationException(qn.toString()+" does not allow sequence with more than one element");
                return ret;
            } catch(SaxonApiException ex) {
                throw new ValidationException(input+" can not be casted to "+qn.toString());
            }
        }
    };
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:31,代码来源:DatatypeFactory.java

示例4: testExtFunctions

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
@Test
public void testExtFunctions() throws Exception {
    Configuration config = new DefaultSaxonConfigurationFactory().getConfiguration();
    Processor proc = new Processor(config);
    XPathCompiler xpc = proc.newXPathCompiler();
    xpc.declareNamespace("ex", "top:marchand:xml:extfunctions");
    QName var = new QName("connect");
    xpc.declareVariable(var);
    XPathExecutable xpe = xpc.compile("ex:basex-query('for $i in 1 to 10 return <test>{$i}</test>',$connect)");
    assertNotNull("unable to compile extension function", xpe);
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:12,代码来源:GauloisPipeTest.java

示例5: XPathCache

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
public XPathCache(Configuration configuration) {
	this.configuration 	= configuration;
	
	final Processor processor 	= new Processor(configuration);
	compiler = processor.newXPathCompiler();

	declareNamespace(KeyRefInterface.NAMESPACE_PREFIX, 		KeyRefInterface.NAMESPACE_URI);
	declareNamespace(KeyDefInterface.NAMESPACE_PREFIX, 		KeyDefInterface.NAMESPACE_URI);
	declareNamespace(XsltConref.NAMESPACE_PREFIX, 			XsltConref.NAMESPACE_URI);
	declareNamespace(XsltConref.NAMESPACE_PARAMETER_PREFIX, XsltConref.NAMESPACE_PARAMETER_URI);
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:12,代码来源:XPathCache.java

示例6: compiler

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
public static synchronized XPathCompiler compiler()
        throws ToolsException
{
    if ( null == COMPILER ) {
        Processor saxon = new Processor(false);
        Library lib = new EXPathFileLibrary();
        lib.register(saxon.getUnderlyingConfiguration());
        COMPILER = saxon.newXPathCompiler();
        COMPILER.declareNamespace(
                EXPathFileLibrary.NS_PREFIX,
                EXPathFileLibrary.NS_URI);
    }
    return COMPILER;
}
 
开发者ID:fgeorges,项目名称:expath-file-java,代码行数:15,代码来源:SaxonTools.java

示例7: XPathEvaluator

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
public XPathEvaluator() {
    // The boolean argument indicates whether this is the licensed edition or not.
    processor = new Processor(false);
    xPathCompiler = processor.newXPathCompiler();
}
 
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:6,代码来源:XPathEvaluator.java

示例8: init

import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
 * Initialization to improve performance for repetitive invocations of filter and evaluate expressions
 * 
 * @throws XPathException
 */
private void init() throws XPathException {
	
	try {
		
		// Get the processor
		proc = new Processor(false);

		// Set any specified configuration properties for the processor
		if (featureMappings != null) {
			for (Entry<String, Object> entry : featureMappings.entrySet()) {
				proc.setConfigurationProperty(entry.getKey(), entry.getValue());
			}
		}
		
		//proc.setConfigurationProperty(FeatureKeys.ENTITY_RESOLVER_CLASS, "com.elsevier.spark_xml_utils.common.IgnoreDoctype");
		
		// Get the XPath compiler
		XPathCompiler xpathCompiler = proc.newXPathCompiler();

		// Set the namespace to prefix mappings
		this.setPrefixNamespaceMappings(xpathCompiler, namespaceMappings);

		// Compile the XPath expression  and get a document builder
		xsel = xpathCompiler.compile(xPathExpression).load();
		builder = proc.newDocumentBuilder();
	
		// Create and initialize the serializer  
		baos = new ByteArrayOutputStream();
		serializer = proc.newSerializer(baos);
		serializer.setOutputStream(baos);
		serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
		serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");			
		serializer.setProcessor(proc);
	
	} catch (SaxonApiException e) {
		
		log.error("Problems creating an XPathProcessor.  " + e.getMessage(),e);
		throw new XPathException(e.getMessage());

	}
	
}
 
开发者ID:elsevierlabs-os,项目名称:spark-xml-utils,代码行数:48,代码来源:XPathProcessor.java


注:本文中的net.sf.saxon.s9api.Processor.newXPathCompiler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。