You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Harald Finster <hf...@gmx.de> on 2008/08/17 19:09:19 UTC

Re: [JXPATH] getting Containers in iteration (additional info)

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?

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


Re: [JXPATH] getting Containers in iteration (additional info)

Posted by Harald Finster <hf...@gmx.de>.
Dear Matt,
dear list-members,

thank you very much for your kind reply.

Matt Benson wrote:

> 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. 

yes, that's clear.
I had (little) hope, that this arbitrariness might be
configurable in some way, but I am certainly asking too much.
(And I don't want to belittle the value of jxpath in any way,
it is a great tool.)

> There are some
> comments at
> https://issues.apache.org/jira/browse/JXPATH-86
> relating to the idea of reading the list property
> directly. 

Thank you for this. The article makes the point
very clear.

> 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.
> 

sounds absolutely plausible - yes.

>>> asking dump questions. (At least I had a look at

"dump" I should learn to write English ;-)


Bottom line: I will write some kind of 'post-processing'.

Again, thanks for your enlightening comments.

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


Re: [JXPATH] getting Containers in iteration (additional info)

Posted by Matt Benson <gu...@yahoo.com>.
--- Harald Finster <hf...@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