Dear All,

I try a very simple example:

mydoc.xml document:


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

<first>
  <second>
    <item type="attvalue">nodevalue</item>
  </second>
</first>


And the Pharo code found in the book.pharo-project.org:

| doc results |
doc := XMLDOMParser parseFileNamed: 'mydoc.xml'.
results := ( XPath for: 'first' ) in: doc.
results explore


As a result, I obtain an empty OrderedCollection...It should contain an element. Then a make some changes using different XPath expressions (i.e. '/first/second/item/@type", etc.) but no way.

Then I discover the first element of the XPath expression must not be the root of the XML doc. If I change the mydoc.xml, introducing a new root element:


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

<foo>
<first>
  <second>
    <item type="attvalue">nodevalue</item>
  </second>
</first>
</foo>

Everything is ok (the same code as above). Here, XPath assumes that the first tag we are looking for is not the root of the doc, otherwise it fails. I'm not so sure but it seems that such implementation doesn't follow the XPath specs. I tried another example from http://www.w3schools.com/xpath/xpath_syntax.asp and same results: I obtain an empty collection when using an XPath expression beginning with the 'bookstore' tag, the root element of the doc:

| doc results |
doc := XMLDOMParser parseFileNamed: 'books.xml'.
results := ( XPath for: '/bookstore' ) in: doc.
results explore

Maybe, I missed something...

Note: I have had to replace the isTag (deprecated) with isElement in some piece of XPath code.

Cheers,

Herve

Reply via email to