Firstly, 8.8 is rather an old version. Please try to reproduce the problem with a later version if you can.
 
One possibility is that you are hitting a bug such as
 
https://sourceforge.net/tracker/index.php?func=detail&aid=1616070&group_id=29872&atid=397617
 
Also, please check that you are actually loading Saxon as the XPath engine, by displaying the class name of the returned "factory" variable.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Rakesh guttal
Sent: 27 February 2008 18:15
To: Michael Kay; saxon-help@lists.sourceforge.net
Subject: [saxon] Issue with XPATH evaluate


Hi Michael,

I am using saxon 8.8 version of your saxon product.
In order to improve the performance , i am using saxon's net.sf.saxon.xpath.XPathFactoryImpl for xpath querying.

here goes Test java file.

/////////////////////////////////////////////////////
public class Test {
        private XPathFactory      factory = null;
     private XPath           xpath = null;
     
     public static void main(String[] args) {
          
          System.setProperty("javax.xml.xpath.XPathFactory:"+XPathConstants.DOM_OBJECT_MODEL,"net.sf.saxon.xpath.XPathFactoryImpl");
          XPathFactory      factory = null;
          XPath           xpath = null;
          
          String objectModel=XPathConstants.DOM_OBJECT_MODEL;
          try {
               factory      = XPathFactory.newInstance(objectModel);
          } catch (XPathFactoryConfigurationException e1) {
               e1.printStackTrace();
          }
          
          xpath           = factory.newXPath();
          Document document = null;
         try {
              System.out.println("before documentbuild");
           DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
           DocumentBuilder db = dbf.newDocumentBuilder();
           Test a = new Test();
           InputStream is = a.getResourceAsInputStream("IUFReportSchema.xsd");
           document = db.parse(is);
           System.out.println("document:"+document);
           is.close();
          
           Node root = document.getDocumentElement();
           NodeList elements = null;
          
              
           String query = "element[@name='option']";
           System.out.println("query="+query);
          
           XPathExpression xpthQuery=xpath.compile(query);
          
           elements = (NodeList)xpthQuery.evaluate( root, XPathConstants.NODESET);
          
           System.out.println("elements size:"+elements.getLength());
           //log.info("Resource file parsed " + filename);
         }
         catch (Exception e) {
           // log.error("Problem parsing [" + filename + "]");
           //log.error("Exception: "+e.getMessage());
         }

  public InputStream getResourceAsInputStream(String filename) {
         return getClass().getClassLoader().getResourceAsStream  (filename);
       }
}
////////////////////////////////////////////////////////

when I run above java file with saxon8-xpath.jar on classpath,i get the below output (which is expected)

elements size:1

But, when I run this file with saxon8-xpath.jar & saxon8sa.jar, i get an unexpected output.

elements size:0

Why is that when i include saxon8sa.jar apart from saxon8-xpath.jar on classpath, it affects the xpath querying result? it's not able to find an element with name "option" and it returns nodelist of size 0.

Regards,
Rakesh



Monster