0

I am trying to evaluate XPath Expression "/feed/entry/title" using:

NodeList nodeList = (NodeList) inputXMLxpath.evaluate("/feed/entry/title", xmlDoc,
                XPathConstants.NODESET);

If the xmlDoc is like this:

<?xml version="1.0" encoding="UTF-8"?>
<feed>
  <entry>...
<feed>

I get proper results, but when xmlDoc is like this:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <entry>...
</feed>

the result of XPath evaluation is always an empty list.

Can anybody tell the reason for this and suggest a solution such that I get proper result in second case also?

Pranav Pal
  • 275
  • 6
  • 18

1 Answers1

1

The xmlns-"...." is a namespace declaration, and it has the effect of changing the names of the elements in the document so that they are no longer called "feed" and "entry", but something more complicated. Google for "XPath default namespace declaration".

Michael Kay
  • 156,231
  • 11
  • 92
  • 164