I'm not sure if your XPathEvaluator is a net.sf.saxon.xpath.XPathEvaluator or a net.sf.saxon.sxpath.XPathEvaluator; but either way, you can't mix s9api and non-s9api interfaces in this way. Since you've built an XdmNode using s9api, please use the s9api XPath API to access it.
Alternatively, you can get the NodeInfo underlying the s9api XdmNode, and pass this to the XPathExpression.evaluate() method.


Michael Kay

From: Steve Carton [mailto:steve.carton@retrievalsystems.com]
Sent: 29 January 2010 15:17
To: saxon-help@lists.sourceforge.net
Subject: [saxon] (no subject)

Hi guys,
I'm trying to write a java program that will parse a file with an XML document and then run an XPath against that XML document. I'm using Dom4J as my parser. I think I'm parsing the document okay, but when I run the XPath, I get this exception:
javax.xml.xpath.XPathExpressionException: Cannot locate an object model implementation for nodes of class net.sf.saxon.s9api.XdmNode
Here is an excerpt from the code:
    SAXReader parser = new SAXReader();
    parser.setEntityResolver(new NoOpEntityResolver());
    Document doc = parser.read(xmlF);
    Configuration configuration = processor.getUnderlyingConfiguration();
    configuration.registerExternalObjectModel(new DOM4JObjectModel());
    net.sf.saxon.functions.FunctionLibrary lib = MyFunctionLibrary.getInstance(configuration);
    configuration.setExtensionBinder("java", lib);
    XPathEvaluator xpathEvaluator = new XPathEvaluator(configuration);
    xpathEvaluator.getStaticContext().setNamespaceContext(new MyNamespaceContext());
    XPathExpression xpathExpression = xpathEvaluator.compile(script);
    String result = xpathExpression.evaluate(processor.newDocumentBuilder().wrap(xml));
Part of the requirement here is to automagically recognize certain prefix bindings and map them to java extension functions. Not sure if that stuff is getting in the way or not.
Any advice or thoughts?
Steve Carton