commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: Collection usage in JXPath commons
Date Mon, 19 Feb 2007 18:11:56 GMT
--- Neil Benn <neil.benn@gmail.com> wrote:

> Hello,
> 
>         I'm sorry to ask such a basic question but I
> have a use case where I
> receive a collection and want to access an element
> of that collection.  I've
> tried several methods to get to an elements,
> iindexing and calling methods
> but to no avail.  The curretn thing I'm trying is
> this :
> 
>     public void testJXContext(){
>         List<String> objTest = new
> ArrayList<String>();
>         objTest.add("test1");
>         objTest.add("test2");
> 
>         JXPathContext objContext =
> JXPathContext.newContext(objTest);
>        
> System.out.println(objContext.getValue("[1]"));
>     }
> 
> However that give eme stack trace of :
> 
> org.apache.commons.jxpath.JXPathException: Invalid
> XPath: '[1]'. Syntax
> error at the beginning of the expression
>     at
>
org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
>     at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpression(
> JXPathContextReferenceImpl.java:218)
>     at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(
> JXPathContextReferenceImpl.java:247)
>     at
>
com.ziath.eventregistration.email.test.EMailFormatterTest.testJXContext(
> EMailFormatterTest.java:18)
>     <snip>
> 
> This is being run through JUnit executing via
> eclipse.
> 
> Could someone be so kind as to let me know what the
> syntaz should be here to
> get it to work?
> 
> Thanks, in advance for your help.

Hi Neil.  Looking at jxpath's
src/test/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java,
it looks like e.g. "/.[0]" should do what you need.

HTH,
Matt

> 
> Cheers,
> 
> Neil
> 



 
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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


Mime
View raw message