commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: [JXPATH] getting Containers in iteration (additional info)
Date Mon, 18 Aug 2008 13:52:07 GMT
--- Harald Finster <hfinster@gmx.de> wrote:

> Hello again,
> 
> I would just like to add  an other observation:
> 
> If I add
>  Map<T,T> map ;
> to my 'Book', I get the 'expected' result for the
> map property ,
> i.e. iterating with "/*" as XPath results in the
> following:
> 
> title      = "Book Title"
> authors[1] = "First Author"
> authors[2] = "Second Author"
> map        = {key1=value1, key2=value2, key3=value3}
> 
> This looks somewhat inconsistent to me?

Remember that JXPath more or less exposes the Java
object graph as an XML document, so the rules it uses
to do so may seem somewhat arbitrary.  There are some
comments at
https://issues.apache.org/jira/browse/JXPATH-86
relating to the idea of reading the list property
directly.  The upshot is that iteration e.g. "/*"
can't yield the collection directly, though you can
select it directly by name/path.  With regard to maps,
the decision was made "in the beginning" to implement
JXPath such that Maps are exposed as bare objects;
note that a Map is not a collection.  Consider that
unless a Map's keys are Strings there is no guarantee
that a reasonable path step could be interpolated for
a given Map entry; this is probably the most direct
reason I could speculate for the decision not to
handle Maps in any special way in JXPath.

HTH,
Matt

> 
> Greetings Harald
> 
> Harald Finster wrote:
> > Hello,
> > 
> > this is my first posting to this list, so forgive
> me, if I am
> > asking dump questions. (At least I had a look at
> the archive.)
> > 
> > I would like to ask, if it is possible to get
> containers
> > (e.g. Lists) 'as they are' in an iteration.
> > 
> > Consider the following bean:
> > 
> > public class Book {
> > 	String title;
> > 	List<Writer> authors;
> > }
> > 
> > Iterating this bean with
> > 
> > JXPathContext context =
> JXPathContext.newContext(book);
> > i = context.iteratePointers("/*");
> > 
> > results in the following:
> > 
> > title      = "Book Title"
> > authors[1] = "First Author"
> > authors[2] = "Second Author"
> > ...
> > 
> > i.e. the List is iterated instead of being
> returned as a List-Object.
> > Obviously, each list-item is regarded as a direct
> child of the root
> > of the Book object.
> > 
> > Is there any way to avoid this behavior?
> > i.e. is it possible to get something like
> > 
> > title   = "Book Title"
> > authors = [ "First Author", "Second Author" ... ]
> i.e. List<Author>
> > 
> > 
> > 
> > In XML-notation the difference would be like this:
> > 
> > The current behavior of 'iterate':
> > 
> > <book>
> > 	<title>Book Title</title>
> > 	<authors>First Author</authors>
> > 	<authors>Second Author</authors>
> > </book>
> > 
> > 
> > what I would like to see is an equivalent of:
> > 
> > <book>
> > 	<title>Book Title</title>
> > 	<authors>
> > 		<1>First Author</1>
> > 		<2>Second Author</2>
> > 	</authors>
> > </book>
> > 
> > 
> > By the way: in contrast to 'iterate'
> 'getValue("authors") returns
> > List<Author>
> > 
> > 
> > I would be grateful for any thoughts and
> suggestions.
> > 
> > With kind regards
> > 
> > Harald
> > 
> > 
> 
> -- 
> Dr.-Ing. Harald Finster / Aachen Germany
> http://www.finster-stahlart.de industrial history
> and architecture
> http://www.astrid-aix.de       gallery: watercolours
> and oil paintings
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@commons.apache.org
> For additional commands, e-mail:
> user-help@commons.apache.org
> 
> 



      

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message