[xml] xpath treatment of absent nodes



I am seeing a difference between command line xpath under linux and libxml. I am wondering which is right.

If I have a tree like this:

<foo>
  <bar id='0'>
   <baz>0</baz>
   <bip>it is zero</bip>
  </bar>
  <bar id='1'>
   <baz>1</baz>
   <bip>it is one</bip>
  </bar>
  <bar id='2'>
   <bip>no baz element</bip>
  </bar>
</foo>

Now if I run xpath, I see:

$ xpath -e '//foo/bar[baz=1]/bip' < test.xml
Found 1 nodes in stdin:
-- NODE --
<bip>it is one</bip>

$ xpath -e '//foo/bar[baz!=1]/bip' < test.xml
Found 2 nodes in stdin:
-- NODE --
<bip>it is zero</bip>
-- NODE --
<bip>no baz element</bip>

That's what I'd expect.

However, libxml's xpath appears to not find the second match (where there is no 'baz') element on the second 
xpath query. Which is right?


-- 
Alex Bligh







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]