[xml] Using Xpath with default namespace and null prefix
- From: IÃaki Baz Castillo <ibc aliax net>
- To: xml gnome org
- Subject: [xml] Using Xpath with default namespace and null prefix
- Date: Mon, 8 Feb 2010 03:08:49 +0100
Hi, I'm user of Nokogiri, a Ruby library warpping libxml2. There is something
I cannot do with Nokogiri and just would like to know if it's feasible by
directly using libmlx2.
Let's suppose the following XML document:
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="urn.default">
<child>Hello</child>
</root>
-------------------------
To get the <child> element I do (supposing @doc contains the parsed XML
object):
@doc.xpath( "/ns:root/ns:child", {"ns"=>"urn.default"} )
I understand that the XML document declares a default namespace in the root
node, so in order to use Xpath I need to include a namespace prefix pointing
to "urn.default" in each node (I don't want to use "/*/*" and so).
Unfortunatelly in my case I'm implementing a XCAP (RFC 4825) client and
server. XCAP reuses Xpath but allows Xpath nodes without prefix matching an
"application specified namespace". This is, the following "Xpath" should work
(given than the application default namespace is "urn.default"):
@doc.xpath( "/root/child" )
so this should return:
<child>Hello</child>
I know that most probably this breaks Xpath 1.0 specification. However I would
like to know if it's possible using libxml2 so I could ask Nokogiri developers
to implement it.
Another possibility also valid for me would be the following:
@doc.xpath( "/root/child", {null => "urn.default"} )
This is, I don't use prefixes in the Xpath nodes but declares "null"
namespace. Not sure if this is possible using libxml2 as for sure it doesn't
make sense within Xpath specification.
Thanks a lot for any help and best regards.
--
IÃaki Baz Castillo <ibc aliax net>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]