--- Neil Benn <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]