I have a problem when calling getJAXBNodesViaXPath("//w:bookmarkStart") (the problem is still there with any other valid xpath expression) on any header, document or footer part, when the part is containing a floating image ("in front of the text").
It's related to my last issue : http://www.docx4java.org/forums/docx-java-f6/classcastexception-org-docx4j-wml-tblpr-cannot-be-cast-t1051.html.
My stack trace :
- Code: Select all
java.lang.RuntimeException: javax.xml.xpath.XPathExpressionException
at org.docx4j.XmlUtils.xpath(XmlUtils.java:922)
at org.docx4j.XmlUtils.xpath(XmlUtils.java:895)
at org.docx4j.XmlUtils.getJAXBNodesViaXPath(XmlUtils.java:873)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getJAXBNodesViaXPath(MainDocumentPart.java:175)
...
Caused by: java.lang.RuntimeException: Unable to evaluate expression using this context
at com.sun.org.apache.xpath.internal.axes.NodeSequence.setRoot(NodeSequence.java:212)
at com.sun.org.apache.xpath.internal.axes.LocPathIterator.execute(LocPathIterator.java:210)
at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:335)
The argument nodehandle of the setRoot(,) method is -1, as node is null in getJAXBNodesViaXPath when called on the part containing the floating image :
- Code: Select all
public static List<Object> getJAXBNodesViaXPath(Binder<Node> binder,
Object jaxbElement, String xpathExpr, boolean refreshXmlFirst)
throws JAXBException {
Node node;
if (refreshXmlFirst)
node = binder.updateXML(jaxbElement);
[color=#FF0000]node = binder.getXMLNode(jaxbElement);[/color]
//log.debug("XPath will execute against: " + XmlUtils.w3CDomNodeToString(node));
List<Object> resultList = new ArrayList<Object>();
for( Node n : xpath(node, xpathExpr) ) {
...
}
Thanks.