in reply to Re^3: xmlns and XML::LibXML ( local-name() )
in thread xmlns and XML::LibXML

I have read all the threads I can find. (Different from understanding them all perhaps) and I have not found the answer

I have been using XML examples from the RFC4918, but the two namespace cases are different in other ways too. So I will construct an example

Is it true that:

<?xml version="1.0" encoding="utf-8" ?> <propfind xmlns="DAV:"> <propname/> </propfind>

and

<?xml version="1.0" encoding="utf-8" ?> <D:propfind xmlns:D="DAV:"> <D:propname/> </D:propfind>

are the same (semantically)?

If so then the same Perl code should parse them, if not I am more confused than I thought

Worik

Update: The same Perl code and Xpath

Replies are listed 'Best First'.
Re^5: xmlns and XML::LibXML ( local-name() )
by choroba (Cardinal) on Jun 02, 2015 at 08:30 UTC
    Yes.
    #! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my @xmls = (<< '__XML1__', << '__XML2__'); <?xml version="1.0" encoding="utf-8" ?> <propfind xmlns="DAV:"> <propname/> </propfind> __XML1__ <?xml version="1.0" encoding="utf-8" ?> <D:propfind xmlns:D="DAV:"> <D:propname/> </D:propfind> __XML2__ for my $xml (@xmls) { my $xpc = 'XML::LibXML::XPathContext'->new; $xpc->registerNs('x', 'DAV:'); my $doc = 'XML::LibXML'->load_xml(string => $xml); say $xpc->find('count(//x:propname)', $doc); }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^5: xmlns and XML::LibXML ( local-name() )
by Anonymous Monk on Jun 02, 2015 at 09:33 UTC
    Is it true that ... and ... are the same (semantically)?

    They both have a root node named "propfind" in the namespace "DAV:" with a child "propname" also in the namespace "DAV:". Which shortcut was used to assign that namespace does not matter.