Skip Menu |

This queue is for tickets about the XML-LibXML CPAN distribution.

Report information
The Basics
Id: 17665
Status: rejected
Priority: 0/
Queue: XML-LibXML

People
Owner: pajas [...] matfyz.cz
Requestors: jjore [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.58
Fixed in: (no value)



Subject: <foo xmlns="..." isn't understood to be in the foo namespace
The following test shows that the namespace prefix isn't being chosen correctly. Given a xmlns declaration without a prefix, the effective prefix is the containing element's name. XML::LibXML pushes the element out of the xml namespace but doesn't apply the sdnList namespace to it or its children. use Test::More tests => 1; use XML::LibXML (); { my $xml = <<'XML'; <?xml version="1.0" standalone="yes"?> <sdnList xmlns="http://tempuri.org/sdnList.xsd"> <sdnEntry> <lastName>Hello world!</lastName> </sdnEntry> </sdnList> XML my $parser = XML::LibXML->new; my $doc = $parser->parse_string($xml); my $result = $doc->findvalue('//sdnList:lastName'); is( $result, "Hello world!", "Namespace" ); }
On Wed Feb 15 18:59:33 2006, JJORE wrote: Show quoted text
> The following test shows that the namespace prefix isn't being chosen > correctly.
No, it is entirely correct. Show quoted text
> Given a xmlns declaration without a prefix, the effective prefix is > the containing element's name. XML::LibXML pushes the element out of > the xml namespace but doesn't apply the sdnList namespace to it or its > children.
This is as the spec demands. From XPath, section 2.3, Node tests: Show quoted text
> A QName in the node test is expanded into an expanded-name using the > namespace declarations from the expression context. This is the same > way expansion is done for element type names in start and end-tags > except that the default namespace declared with xmlns is not used: if > the QName does not have a prefix, then the namespace URI is null (this > is the same way attribute names are expanded).
To further quote Daniel Veillard, author of libxml2, in <http://mail.gnome.org/archives/xml/2003-April/msg00144.html>: Show quoted text
> You cannot define a default namespace for XPath, period, don't try you > can't, the XPath spec does not allow it. This can't work and trying to > add it to libxml2 would simply make it non conformant to the spec. > > In a nutshell forget about using default namespace within XPath > expressions, this will *never* work, you *can't* !
CC: JJORE [...] cpan.org
Subject: Re: [rt.cpan.org #17665] <foo xmlns="..." isn't understood to be in the foo namespace
Date: Sun, 19 Feb 2006 23:31:57 -0600
To: bug-XML-LibXML [...] rt.cpan.org
From: "Joshua ben Jore" <twists [...] gmail.com>
On 2/19/06, via RT <bug-XML-LibXML@rt.cpan.org> wrote: Show quoted text
> On Wed Feb 15 18:59:33 2006, JJORE wrote:
> > The following test shows that the namespace prefix isn't being chosen > > correctly.
> > No, it is entirely correct. >
> > Given a xmlns declaration without a prefix, the effective prefix is > > the containing element's name. XML::LibXML pushes the element out of > > the xml namespace but doesn't apply the sdnList namespace to it or its > > children.
> > This is as the spec demands. From XPath, section 2.3, Node tests: >
> > A QName in the node test is expanded into an expanded-name using the > > namespace declarations from the expression context. This is the same > > way expansion is done for element type names in start and end-tags > > except that the default namespace declared with xmlns is not used: if > > the QName does not have a prefix, then the namespace URI is null (this > > is the same way attribute names are expanded).
> > To further quote Daniel Veillard, author of libxml2, in > <http://mail.gnome.org/archives/xml/2003-April/msg00144.html>: >
> > You cannot define a default namespace for XPath, period, don't try you > > can't, the XPath spec does not allow it. This can't work and trying to > > add it to libxml2 would simply make it non conformant to the spec. > > > > In a nutshell forget about using default namespace within XPath > > expressions, this will *never* work, you *can't* !
>
Am I to interpret this to mean that XML that declares a default namespace cannot be queried by XPath or do you mean that I can't expect XPath to start in some default namespace? I'd be perfectly happy changing my query or making some appropriate calls to libxm2's API to inform it of the namespace to make the queries from. Is the XML not valid? What? Josh
On Mon Feb 20 00:32:53 2006, twists@gmail.com wrote: Show quoted text
> Am I to interpret this to mean that XML that declares a default > namespace cannot be queried by XPath or do you mean that I can't > expect XPath to start in some default namespace?
No. It just means that it does not matter which prefix the namespace in question is bound to in the XML document. In XPath, an element name without a prefix always matches that element in the null namespace. If you want to match that element in some namespace, regardless of which prefix is bound to that namespace in the XML document, you have to bind the namespace to a prefix in the XPath context and then use that prefix in the XPath expression. Show quoted text
> I'd be perfectly happy changing my query or making some appropriate > calls to libxm2's API to inform it of the namespace to make the > queries from.
Yep, that’s what you need to do. In case of XML::LibXML, that means using XML::LibXML::XPathContext, which must be installed separately. To be honest, I’m annoyed that that doesn’t come bundled with XML::LibXML, because there’s no way to do real-world work on XML documents with XPath without using ::XPathContext. Show quoted text
> Is the XML not valid? What?
The XML wouldn’t even parse if it weren’t just fine. :-)