Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-467

Unable to selectPath() on an element with a specific attribute value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Version 2, Version 2.2, Version 2.2.1, Version 2.3, Version 2.4 , Version 2.5.1
    • None
    • XPath
    • None
    • Windows XP/AIX 5.3
      Java 1.6 32-bit on Windows / Java 6 64-bit on AIX

    Description

      As titled. Here's some sample code:

      public static void main(String args[]) {

      XmlObject xml = XmlObject.Factory.newInstance();
      try

      { /* <Sample> <path1>FirstValue</path1> <list> <param name="number">123456789</param> <param name="status">Active</param> </list> </Sample> * */ xml = XmlObject.Factory.parse("<Sample><path1>FirstValue</path1><list><param name=\"number\">123456789</param><param name=\"status\">Active</param></list></Sample>"); }

      catch (Exception e) {};
      System.out.println("XML = " + xml.xmlText());

      String cacheXPath1 = "Sample/path1";
      String cacheXPath2 = "Sample/list/param[@name='status']";
      XmlCursor c = xml.newCursor();
      c.selectPath(cacheXPath1);

      String value = "";
      if (c.toNextSelection())

      { value = c.getTextValue(); }
      System.out.println("Value of " + cacheXPath1 + " is " + value);

      value = "";
      c.dispose();
      c = xml.newCursor();
      c.selectPath(cacheXPath2);
      if (c.toNextSelection()) { value = c.getTextValue(); }

      System.out.println("Value of " + cacheXPath2 + " is " + value);

      c.dispose();
      }

      The output I get is

      Value of Sample/path1 is FirstValue
      Exception in thread "main" java.lang.RuntimeException: Trying XBeans path engine... Trying XQRL... Trying delegated path engine... FAILED on Sample/list/param[@name='status']
      at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:173)
      at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:130)
      at org.apache.xmlbeans.impl.store.Cursor._selectPath(Cursor.java:902)
      at org.apache.xmlbeans.impl.store.Cursor._selectPath(Cursor.java:894)
      at org.apache.xmlbeans.impl.store.Cursor.selectPath(Cursor.java:2616)
      at test.Test1.main(Test1.java:49)

      So it was not able to find the element <param> that has a value of "Active" for the "status" attribute. I've tried XMLBeans 2.4 from Apache site, and also versions 2.2 and 2.5.1 that come with Weblogic Server 10.3.3. Any help would be appreciated.

      Attachments

        Activity

          People

            Unassigned Unassigned
            pmak Paul Mak
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: