xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffan Westcott (JIRA)" <xmlbeans-...@xml.apache.org>
Subject [jira] Created: (XMLBEANS-331) Deleting text node causes some XPath select queries to fail
Date Fri, 25 May 2007 15:23:16 GMT
Deleting text node causes some XPath select queries to fail
-----------------------------------------------------------

                 Key: XMLBEANS-331
                 URL: https://issues.apache.org/jira/browse/XMLBEANS-331
             Project: XMLBeans
          Issue Type: Bug
          Components: XPath
    Affects Versions: Version 2.1, Version 2.2
         Environment: Windows XP Service Pack 2, JDK 1.6.0_01
            Reporter: Steffan Westcott


Deleting TEXT tokens in a document appears to confuse the selectPath() functionality. Here
is a complete demonstration program :


package bug;

import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;

public class Bug {

    static String doc ="<?xml version='1.0' encoding='UTF-8'?><a><b/>text<b/></a>";
    static String query = "//b[2]";
    
    public static void main(String[] args) {
        try {
            // Initialise XmlObject and cursor
            XmlObject obj = XmlObject.Factory.parse(doc);
            System.out.println("Intitial document :\n" + obj.toString());
            XmlCursor cur = obj.newCursor();
            
            // Select the second b node - Works fine...
            cur.selectPath(query);
            System.out.println(query + " finds " + cur.getSelectionCount() + " objects");
            
            // Delete the text node
            cur.toStartDoc();
            cur.selectPath("/a/text()");
            cur.toSelection(0);
            cur.removeXml();
            System.out.println("After removing text node :\n" + obj.toString());
            
            // Select the second b node - Doesn't work!!!
            cur.selectPath(query);
            System.out.println(query + " finds " + cur.getSelectionCount() + " objects");
            
            cur.dispose();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


This produces the following output :

Intitial document :
<a>
  <b/>
  text
  <b/>
</a>
//b[2] finds 1 objects
After removing text node :
<a>
  <b/>
  <b/>
</a>
//b[2] finds 0 objects


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


Mime
View raw message