[libxml-devel] Specifying namespace on XPath?
keisuke fukuda
keisukefukuda at gmail.com
Tue Nov 27 00:29:44 EST 2007
Hi,
How to specify namespace on xpath in version 5.2.0 ?
Someone told me that you can do it like this in version 3.8.4 :
---
require "rubygems"
require "xml/libxml" # 3.8.4
doc = XML::Parser.string(<<EOS).parse
<?xml version="1.0" encoding='utf-8'?>
<service xmlns="http://www.w3.org/2007/app"
xmlns:atom="http://www.w3.org/2005/Atom">
<workspace>
<collection href="http://example.org/blog/main">
<atom:title>My Blog Entries</atom:title>
</collection>
</workspace>
</service>
EOS
namespaces = {
"app" => "http://www.w3.org/2007/app",
"atom" => "http://www.w3.org/2005/Atom"
}.to_a
p doc.find('/app:service/app:workspace/app:collection/atom:title', namespaces)
__END__
=> <atom:title>My Blog Entries</atom:title>
---
But, in 5.2.0, it saids
" in `find': nested array must be an array of strings, prefix and
href/uri (ArgumentError) "
( in Addition, it SEGVs sometimes in normal interpreter and always in irb )
Is this a bug ? (Or, is there any other way to do this in 5.2.0) ?
I took a look at the source code and found that there is almost no
unit test about namespace on XPath.
--
FUKUDA, Keisuke
More information about the libxml-devel
mailing list