empty xpath evaluations on add-on deployment

Post here questions and problems related to oXygen frameworks/document types.
LBarth
Posts: 23

empty xpath evaluations on add-on deployment

Fri Jul 10, 2015 5:15 pm

Hi,

I have developed a plugin and framework I want to push as add-ons on our website.

The plugin works perfectly on my mac, in debug mode in eclipse and in direct mode after compiling the jar.

I use a laptop on which I have downloaded a trial version of oxygen author to check the add-on deployment.

The deployment itself is ok but I have a strange problem :
xpath evaluations find nodes on my development machine (in debug mode in eclipse as in direct mode) and return an empty set on the laptop.

I have checked on the laptop the xml file (an xml schema actually) is found, it is readable, it is not empty.
I can access it with getElementsByTagName, I have added a message to display the count of nodes found by xpath evaluate and by getElementsByTagName, it is allways (0, 677) on the laptop and (34, 677) on my pc.

Here is what I do :

Code: Select all

    String xpathstring = "//xs:enumeration[@value='no']"; // can be any xpath
    String xsdSchemaUri = frameworkPath.concat(ROUTARD_URL.XSD_SCHEMA);;
   
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    XPathExpression expr;
    XPath xpath = XPathFactory.newInstance().newXPath();
    Document xmlfile;

    try {
      builder = domFactory.newDocumentBuilder();
      xmlfile = builder.parse(xsdSchemaUri);
    } catch (ParserConfigurationException e) {
      ...
    }

    try {
      expr = xpath.compile(xpathstring);
     
      NodeList nodesTEST = xmlfile.getElementsByTagName("xs:element");

      NodeList nodes = (NodeList) expr
          .evaluate(xmlfile, XPathConstants.NODESET);
         
      pluginWorkspaceAccess.showErrorMessage(xsdSchemaUri + "\n"
          + Integer.toString(nodes.getLength()) + "\n"
          + Integer.toString(nodesTEST.getLength()));
      ...
    }

I have no error message or warning of any kind.
I have checked the java versions, the problem is the same in java 1.6 or in java 1.8.

What else can I check ?

Best regards,
Lionel
Radu
Posts: 5221

Re: empty xpath evaluations on add-on deployment

Mon Jul 13, 2015 12:35 pm

Hi Lionel,

Could you try instead of using this XPath //xs:enumeration[@value='no'] to use //*:enumeration[@value='no']?
It's possible that the XPath evaluator does not know to what namespace the xs prefix is resolved.

You could also add some logging to output the value of the variable's class name xpath.getClass() and also for builder.getClass(). Because we need to make sure what actual implementations are used to create the DOM document and to run the XPath (ideally the Xerces parser would be used to create the DOM Builder and the Saxon 9 processor would be used to run the XPath expression).

You could compare the results with doing that in your development version.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
LBarth
Posts: 23

Re: empty xpath evaluations on add-on deployment

Wed Jul 15, 2015 3:29 pm

Hi radu,

The use of "//*:enumeration[@value='no']" does not work, it gives an exception :
XPathExpressionException org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace :
and the 'xs' prefix is known on the development platform with the very same xsd schema.

The logging you suggested give interesting results :

on the development platform :
builderClass=class org.apache.xerces.jaxp.DocumentBuilderImpl
xpathClass=class net.sf.saxon.xpath.XPathEvaluator

on the laptop :
builderClass=class org.apache.xerces.jaxp.DocumentBuilderImpl
xpathClass=class org.apache.xpath.jaxp.XPathImpl

The xpathClass is different, I checked in the Author options but I didn't find how to enforce the use of net.sf.saxon.xpath.XPathEvaluator.

I also checked on a third platform where everyting is ok, just as on the development platform.

Best regards,
Lionel
Radu
Posts: 5221

Re: empty xpath evaluations on add-on deployment

Wed Jul 15, 2015 3:34 pm

Hi Lionel,

The xpathClass is different, I checked in the Author options but I didn't find how to enforce the use of net.sf.saxon.xpath.XPathEvaluator.


You can probably call directly:

Code: Select all

net.sf.saxon.xpath.XPathFactoryImpl.XPathFactoryImpl().newXPath()


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests