commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shamik Bandopadhyay <>
Subject [jxpath] Issue in retrieving value jxpath
Date Wed, 21 Sep 2011 14:54:42 GMT

 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="" xmlns:media="" xmlns:openSearch="" xmlns:gd="" xmlns:yt="">


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

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.


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