Project

Profile

Help

Cannot locate an object model implementation

Added by Anonymous about 15 years ago

Legacy ID: #6729899 Legacy Poster: nerd (vivianl)

Hi, I have downloaded saxonsa9-1-0-5j, to use its XPath2.0 capability. I created a Java project, and only used two libraries from the saxonsa package: saxon9sa.jar, and saxon9-xpath.jar, because i only want to be able to parse an XPath expression against a XML document. My code is exactly the same as XPathExampleDOM.java, and I only passed in a very simple XPath query to return the first node in an XML document. However, I could never get any result back, it always throws this exception: Exception in thread "main" javax.xml.xpath.XPathExpressionException: Cannot locate an object model implementation for nodes of class com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:297) at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:372) I googled it, found someone else had similar problem, and suggested there is something wrong with the META-INF javax.xml.xpath.XPathFactory file, so i modified this line: http://java.sun.com/jaxp/xpath/dom: com.sun.org.apache.xpath.internal.jaxp.XPathImpl but it still doesn't work, can anyone shade some light on this? Thanks


Replies (5)

Please register to reply

RE: Cannot locate an object model implementation - Added by Anonymous about 15 years ago

Legacy ID: #6730594 Legacy Poster: Michael Kay (mhkay)

To use DOM input with Saxon, you need saxon9-dom.jar on the classpath. Do be aware that using DOM with Saxon is slower - sometimes 10x slower - than using Saxon's native tree structure.

RE: Cannot locate an object model implementat - Added by Anonymous about 15 years ago

Legacy ID: #6746873 Legacy Poster: nerd (vivianl)

Hi Michael, Thanks. It worked after I put saxon9-dom.jar on the classpath. However, I found it very strange that if the XML document I am trying to parse, has a namespace declared, then the evaluate method always return nothing. if I comment out the namespace, it worked - but, the returned result is not a NodeList, but an ArrayList. p.s. I did set the docBuilderFactory.setNamespaceAware(true); Here is the XML document snippet: <?xml version="1.0" encoding="UTF-8"?> <Symptoms> <!-- xmlns="http://docs.oasis-open.org/symptoms/symptoms_v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://docs.oasis-open.org/symptoms/symptoms_v1 file:/Users/dsnelling/Projects/Symptoms/Symptoms_V01.xsd"> --> <Symptom> <InstanceId>urn:0001</InstanceId> <SymptomType>urn:Message_Symptom</SymptomType> <TimeStamp>2009-02-26T00:01:00.00Z</TimeStamp> <Confidence>HighConfidence</Confidence> <Reporter>url:manager.mine.com/Emitter_001</Reporter> <Subject>url:scheduler.mine.com/Sched_001</Subject> <Content> <Message componentName="APPSRVMN">"INFO:bobcat_command, command"</Message> </Content> </Symptom> ... What have I done wrong here? Thanks, Vivian

RE: Cannot locate an object model implementat - Added by Anonymous about 15 years ago

Legacy ID: #6747098 Legacy Poster: Michael Kay (mhkay)

On the first point, you haven't shown your XPath expression, and I would therefore assume you have made the common mistake of thinking that //x will select x elements that are in the default namespace, whereas in fact it selects x elements that are in no namespace. To fix this you need to write //p:x and bind the prefix p to the correct namespace. One the second point, there is a known bug causing this in 9.1.0.5: http://sourceforge.net/tracker2/?func=detail&amp;aid=2514260&amp;group_id=29872&amp;atid=397617 Michael Kay http://www.saxonica.com/

RE: Cannot locate an object model implementat - Added by Anonymous about 15 years ago

Legacy ID: #6748901 Legacy Poster: nerd (vivianl)

You are absolutely right - I didn't put any prefix in. I tried to use prefix, and use the following binding, but didn't get anything: ... docBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Node nodeDoc = docBuilder.parse(is); String exp = new String ("sym:Symptoms");//"*[local-name()]='Symptoms'"); IndependentContext ic = new IndependentContext(); ic.declareNamespace("sym", "http://docs.oasis-open.org/symptoms/symptoms_v1"); NamespaceContext nc = new NamespaceContextImpl(ic); xpath.setNamespaceContext(nc); ... there is no sample code on how to do bindings... any hint? Many Thanks, Vivian

RE: Cannot locate an object model implementat - Added by Anonymous about 15 years ago

Legacy ID: #6749662 Legacy Poster: Michael Kay (mhkay)

Your code looks OK to me, so far as it goes. Perhaps it would be worth supplying the full working example.

    (1-5/5)

    Please register to reply