Page 1 of 1

getJAXBNodesViaXPath Exceptions

PostPosted: Thu Feb 03, 2011 5:41 pm
by Julienoune
Hello all

I have an exception when I'm trying to run the following code :
Code: Select all
Body body = (Body) main.getJAXBNodesViaXPath("//w:body", true).get(0);


Code: Select all
javax.xml.transform.TransformerException: Unable to evaluate expression using this context
        at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:363)
        at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(XPathImpl.java:213)
        at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:275)
        at org.docx4j.XmlUtils.xpath(XmlUtils.java:778)
        at org.docx4j.XmlUtils.xpath(XmlUtils.java:765)
        at org.docx4j.XmlUtils.getJAXBNodesViaXPath(XmlUtils.java:750)
        at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getJAXBNodesViaXPath(MainDocumentPart.java:138)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
        at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)


I've checked into the docx document if my w:body is present.

Any idea why I'v got this exception??

Environment :
Windows XP
grails-1.3.4
docx4j-2.5.0.jar
JAXB: Using Java 6 implementation.

Julien

Re: getJAXBNodesViaXPath Exceptions

PostPosted: Fri Feb 04, 2011 10:11 am
by Julienoune
Hello folks.

My error came from that I executed marshalling and unmarshalling on the main document part before the main.getJAXBNodesViaXPath("//w:body", true) call.

So the xpath instruction is unable to found my w:body node.
I have read about the JAXB bug about the reloading parameter.

Not a big issue, I have just moved my call to Xpath before the marshalling and unmarshalling.
Hope its helps.

Cheers.