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


Java XPathCompiler.declareNamespace方法代码示例

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


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

示例1: evaluateXPath2

import net.sf.saxon.s9api.XPathCompiler; //导入方法依赖的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

示例2: initialize

import net.sf.saxon.s9api.XPathCompiler; //导入方法依赖的package包/类
@Override
public void initialize(InputSplit inSplit, TaskAttemptContext context)
        throws IOException, InterruptedException {
    Path file = ((FileSplit)inSplit).getPath();
    FileSystem fs = file.getFileSystem(context.getConfiguration());
    FSDataInputStream fileIn = fs.open(file);
    DocumentBuilder docBuilder = builderLocal.get();
    try {
        Document document = docBuilder.parse(fileIn);
        net.sf.saxon.s9api.DocumentBuilder db = saxonBuilderLocal.get();
        XdmNode xdmDoc = db.wrap(document);
        XPathCompiler xpath = proc.newXPathCompiler();
        xpath.declareNamespace("wp", 
                "http://www.mediawiki.org/xml/export-0.4/");
        XPathSelector selector = xpath.compile(PATH_EXPRESSION).load();
        selector.setContextItem(xdmDoc);
        items = new ArrayList<XdmItem>();
        for (XdmItem item : selector) {
            items.add(item);
        }
    } catch (SAXException ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } catch (SaxonApiException e) {
        e.printStackTrace();
    } finally {
        if (fileIn != null) {
            fileIn.close();
        }
    }
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:32,代码来源:LinkCountHDFS.java

示例3: constructElementParserDatatype

import net.sf.saxon.s9api.XPathCompiler; //导入方法依赖的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.XPathCompiler; //导入方法依赖的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: setPrefixNamespaceMappings

import net.sf.saxon.s9api.XPathCompiler; //导入方法依赖的package包/类
/**
 * Set the namespaces in the XPathCompiler.
 * 
 * @param xpathCompiler
 * @param namespaceMappings Namespace prefix to Namespace uri mappings
 */
private  void setPrefixNamespaceMappings(XPathCompiler xpathCompiler, HashMap<String,String> namespaceMappings) {

	if (namespaceMappings != null) {
		
		// Get the mappings
		Set<Entry<String, String>> mappings = namespaceMappings.entrySet();		
	
		// If mappings exist, set the namespaces
		if (mappings != null) {
		
			Iterator<Entry<String, String>> it = mappings.iterator();
			while (it.hasNext()) {
				Entry<String, String> entry = it.next();
				xpathCompiler.declareNamespace(entry.getKey(), entry.getValue());					
			}
			
		}
		
	}
	
	// Add in the defaults	
	xpathCompiler.declareNamespace("xml",NamespaceConstant.XML);
	xpathCompiler.declareNamespace("xs",NamespaceConstant.SCHEMA);
	xpathCompiler.declareNamespace("fn",NamespaceConstant.FN);

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


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