You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Steffan Westcott (JIRA)" <xm...@xml.apache.org> on 2007/05/26 20:06:18 UTC
[jira] Updated: (XMLBEANS-331) Deleting text node causes some XPath
select queries to fail
[ https://issues.apache.org/jira/browse/XMLBEANS-331?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Steffan Westcott updated XMLBEANS-331:
--------------------------------------
Description:
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
Deleting ATTR, START (i.e. a whole element), COMMENT and PROCINST tokens do not exhibit this problem, it appears to only affect TEXT tokens.
was:
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
Adding further info that deleting non-TEXT tokens does not have same problem.
> 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
> Deleting ATTR, START (i.e. a whole element), COMMENT and PROCINST tokens do not exhibit this problem, it appears to only affect TEXT tokens.
--
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