commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shirasu hiroyuki <hi...@s9.dion.ne.jp>
Subject Re: JXPath xml file loading
Date Tue, 15 Feb 2005 06:38:12 GMT
Hello,

Try the following:
1. write your XPath expression "locations/address/street",
2. add modifier 'public' to the class Address,
3. check the location of your file 'address.xml' again.

Thanks,
--
shirasu hiroyuki(hirsh@s9.dion.ne.jp)


From: Anton Stoyanov <anton.stoyanov@gmail.com>
Subject: JXPath xml file loading
Date: Tue, 15 Feb 2005 04:43:38 +0100

> Hi guys, 
> 
> probably the easiest of things, but I can't get it to work , can you
> help me please (the example from the manual)
> 
> 
> 
> import org.apache.commons.jxpath.JXPathContext;
> import java.net.URL;
> import org.apache.commons.jxpath.Container;
> import org.apache.commons.jxpath.xml.DocumentContainer;
> 
> 
> 
> public class test {
>     
>     public static void main(String[] args) {
>         JXPathContext  context = JXPathContext.newContext(new Address());
>         String street = (String)context.getValue( "address/street");
>     }
> }
> 
> class Address {
>     private Container locations = null;
> 
>     public Container getLocations(){
>         if (locations == null){
>             URL url = getClass().getResource("address.xml");
>             locations = new DocumentContainer(url);
>         }
>         return locations;
>     }
>  }
> 
> 
> 
> with and address.xml of just:
> 
> <?xml version="1.0" ?>
> <address>
> <street>test</street>
> </address>
> 
> 
> 
> gives me an error : 
> org.apache.commons.jxpath.JXPathException: No value for xpath: address/street
> 	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:344)
> 	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:280)
> 	at test.main(test.java:26)
> Exception in thread "main" 
> 
> 
> 
> 
> any ideas ? 
> 
> thanks alot.
> 
> 
> 
> -- 
> ----------------------
> Anton Stoyanov
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 

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