[libxml-devel] xpath searching without specifying namespace?

mortee mortee.lists at kavemalna.hu
Sun Nov 4 04:16:03 EST 2007


Dan Janowski wrote:
> To do this, please send a sample xml document and ruby code using  
> libxml that illustrates the problem clearly and (hopefully) compactly  
> and indicate what you are expecting but not getting and I will peer  
> into the fog of namespaces (a component I have not updated).

OK, here it is. I have attached two example XML files - one with a
namespace declared on the root node (test-ns.xml), and one without
(test-nons.xml). This is the only difference between them.

Here's what I get for them. Everything's just as expected, except that
the first find should return 2 as well.

$ irb
irb(main):001:0> require 'xml/libxml'
=> true
irb(main):002:0>
XML::Document.file('test-ns.xml').find('nodes/subnode').size
        => 0
irb(main):003:0>
XML::Document.file('test-nons.xml').find('nodes/subnode').size
=> 2
irb(main):004:0>
XML::Document.file('test-ns.xml').find('myns:nodes/myns:subnode',
'myns:http://some-ns.com/').size
=> 2

The docs here say that if I don't specify a namespace on the search,
then any NS may be matched:

http://web.archive.org/web/20070208211112/http://libxml.rubyforge.org/doc/classes/XML/XPath.html

As a side note, the API Docs link is broken on the new front page,
taht's why I included this cached copy.

mortee
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-nons.xml
Type: text/xml
Size: 244 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/libxml-devel/attachments/20071104/f2307e95/attachment.xml 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-ns.xml
Type: text/xml
Size: 286 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/libxml-devel/attachments/20071104/f2307e95/attachment-0001.xml 


More information about the libxml-devel mailing list