Details
Description
I can execute an XPath on an XMLBeans derived class using selectPath(...) and it will behave as expected; returning 0-n results in an XmlObject[] array. However, if I create a copy of the object and execute an XPath on it, every XPath will return a zero-length array.
The examples behave properly with XMLBeans 2.3.0 with Saxon 8.8. I noticed this issue when I switched to XMLBeans 2.4.0 and Saxon 9.0.0.4. The issue remains if I use XMLBeans 2.4.0 and Saxon 9.1.0.6 (the current release at the time of this posting).
So, given this example:
<AppDoc>
<Applications>
<ApplicationType>
<Name>foobar</Name>
</ApplicationType>
<Applications>
</AppDoc>
/**
Say we pass in the ApplicationType object with the Name of "foobar"
**/
public void confuseTheDeveloper( ApplicationType app ){
String xPath = "$this/*:Name";
ApplicationType appCopy = (ApplicationType)app.copy();
XmlObject[] objs = app.selectPath( xPath );
XmlObject[] otherObjs = appCopy.selectPath( xPath );
System.out.prinln( objs.length > 0 ); // prints 'true' ... like it should
System.out.println( otherObjs.length > 0 ); // prints 'false' ...even though it should print 'true'
}
/**
Another example
**/
public void moreConfusion(){
ApplicationType app = ApplicationType.Factory.newInstance();
app.setName( "foobar" );
XmlObject[] objs = app.selectPath( "$this/*:Name" );
System.out.println( objs.length > 0 ); // prints false
}
Changing org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath, method selectNodes, line(s)
NodeInfo contextItem =
//config.buildDocument(new DOMSource(contextNode));
config.unravel(new DOMSource(contextNode));
to
DocumentWrapper contextItem =
new DocumentWrapper(contextNode, contextNode.getNamespaceURI(), config);
appears to restore XPath capabilities for document fragments. The XQuery adapter
org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery may require modification as well.