commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil Benn" <neil.b...@ziath.com>
Subject Accessing a collection with JXPath
Date Sun, 18 Feb 2007 10:39:17 GMT
Hello,
 
            Apologies if this appears again, I sent it from my gmail
account but I think it got picked up as spam.
 
---
 
        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, indexing
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 gives me a 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.compileExpressio
n(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>


  I've tried various syntax for the JKPath including:
 
[1]
/[1]
get(1)
/get(1)
 
  I've also tried making a holder object with a public variable of list
and used list, /list etc.  I can't seem to get the right thing to work!

This is being run through JUnit executing via eclipse.  

Could someone be so kind as to let me know what the syntax should be
here to get it to work?

Thanks, in advance for your help.

Cheers,

Neil
 
 
---
Neil Benn Msc
CEO Ziath Ltd
Website - http://www.ziath.com
Blog - http://labauto-lounge.com
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message