commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Benson (JIRA)" <>
Subject [jira] Resolved: (JXPATH-86) Children returned instead of self for arrays when using . selector
Date Tue, 29 May 2007 23:04:15 GMT


Matt Benson resolved JXPATH-86.

    Resolution: Invalid

This comes down to another misunderstanding wrt the JXPath XPath implementation.  The JXPath
users guide has the following to say, under "Object Graph Traversal"->"Containers":

    For example, if property "foo" of the context node has a Container as its value, the XPath
"foo" will produce the contents of that Container, not the container itself.

Remember that JXPath functions by "pretending" a Java object graph is an XML document.  Think
of this implementation decision as a conscious choice of:
  <foo />
  <foo />


    <foo_child />
    <foo_child />

This seems to have been a more sensible solution than trying to autogenerate an element name
as has been done in the second case.  Finally, as JXPath is headed for a 1.3 release in the
near future, I urge you to conduct any further testing against SVN HEAD so that you might
have an opportunity to review the codebase planned for release for consistency with what I
have said here, and with the users' guide, and to be sure that any further examples you submit
are fully reproducible.  It might be good to conduct discussions on the commons-user mailing
list (preface subjects with [jxpath]) until the determination has been made of items' bug


> Children returned instead of self for arrays when using . selector
> ------------------------------------------------------------------
>                 Key: JXPATH-86
>                 URL:
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.2 Final
>            Reporter: Adam Crume
> The . selector should always return the context node, and the * selector should return
child elements.  However, this doesn't work for arrays:
> JXPathContext context = JXPathContext.newContext(new HashMap());
> context.setValue("array", new String[] {"one", "two", "three"});
> context.setValue("array2", new String[][] { {"a", "b"}, {"c", "d"}});
> context.setValue("person", new Person("Bob", 25));
> String[] paths = {"/array", "/array/.", "/array/*", "/person", "/person/.", "/person/*"};
> for(int i = 0; i < paths.length; i++) {
> 	Pointer pointer = context.getPointer(paths[i]);
> 	System.out.println(pointer.asPath());
> 	Object value = context.getValue(paths[i]);
> 	System.out.println(value);
> 	System.out.println();
> }
> This produces the following output:
> /.[@name='array']
> [Ljava.lang.String;@59b659b6
> /.[@name='array'][1]
> one
> /.[@name='array'][1]/bytes[1]
> 111
> /.[@name='person']
> net.cts.jxpathserializer.Person@760076
> /.[@name='person']
> net.cts.jxpathserializer.Person@760076
> /.[@name='person']/age
> 25

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:
For additional commands, e-mail:

View raw message