Re: [jxpath] Issue in retrieving value jxpath

2011-09-23 Thread Matt Benson
On Wed, Sep 21, 2011 at 9:54 AM, Shamik Bandopadhyay sham...@gmail.com wrote:
 Hi,

  I'm having an issue in parsing the following XML using jxpath. Here's the
 sample XML.

  ?xml version=1.0 encoding=UTF-8?
 feed xmlns=http://www.w3.org/2005/Atom; xmlns:media=
 http://search.yahoo.com/mrss/; xmlns:openSearch=
 http://a9.com/-/spec/opensearchrss/1.0/; xmlns:gd=
 http://schemas.google.com/g/2005; xmlns:yt=
 http://gdata.youtube.com/schemas/2007;
  entry
    idhttp://gdata.youtube.com/feeds/api/videos/P1lDDu9L5YQ/id
    published2010-09-20T17:41:38.000Z/published
   /entry

    entry
       idhttp://gdata.youtube.com/feeds/api/videos/P1lDDu9L5YQ/id
         published2010-09-20T17:41:38.000Z/published
      /entry
 /feed


 I'm trying to read the contents of entry usig xpath. Heres my code
 snippet.

 String test = the_xml_example_above;

 ByteArrayInputStream is = new ByteArrayInputStream(test.getBytes(UTF-8));
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 DocumentBuilder db = dbf.newDocumentBuilder();
 Document doc22 = db.parse(is);

 JXPathContext ctx = JXPathContext.newContext(doc22);
 List nodes = ctx.selectNodes(/feed/entry);

  Here the list is always 0. Now, if I remove the namespace attributes from
 feed, jxpath is able to resolve the entry nodes. Not sure what's the
 reason behind this.

 I'll appreciate if someone cane provide pointers to this issue.

You've most likely identified your issue yourself.  It should work for
you to choose a prefix to use in your xpath queries, and register that
prefix to the Atom namespace before querying.

Matt


 -Thanks


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



[jxpath] Issue in retrieving value jxpath

2011-09-21 Thread Shamik Bandopadhyay
Hi,

 I'm having an issue in parsing the following XML using jxpath. Here's the
sample XML.

 ?xml version=1.0 encoding=UTF-8?
feed xmlns=http://www.w3.org/2005/Atom; xmlns:media=
http://search.yahoo.com/mrss/; xmlns:openSearch=
http://a9.com/-/spec/opensearchrss/1.0/; xmlns:gd=
http://schemas.google.com/g/2005; xmlns:yt=
http://gdata.youtube.com/schemas/2007;
  entry
idhttp://gdata.youtube.com/feeds/api/videos/P1lDDu9L5YQ/id
published2010-09-20T17:41:38.000Z/published
   /entry

entry
   idhttp://gdata.youtube.com/feeds/api/videos/P1lDDu9L5YQ/id
 published2010-09-20T17:41:38.000Z/published
  /entry
/feed


I'm trying to read the contents of entry usig xpath. Heres my code
snippet.

String test = the_xml_example_above;

ByteArrayInputStream is = new ByteArrayInputStream(test.getBytes(UTF-8));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc22 = db.parse(is);

JXPathContext ctx = JXPathContext.newContext(doc22);
List nodes = ctx.selectNodes(/feed/entry);

 Here the list is always 0. Now, if I remove the namespace attributes from
feed, jxpath is able to resolve the entry nodes. Not sure what's the
reason behind this.

I'll appreciate if someone cane provide pointers to this issue.

-Thanks