http://qs321.pair.com?node_id=1089055


in reply to XML::LibXML and Namespace… I don't get it

The namespace is this bit:

xmlns="http://www.w3.org/1999/xhtml"

Not this bit:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

So you should be setting up your XPath context like this:

$xpc->registerNs( xml => "http://www.w3.org/1999/xhtml" );

That said, it's probably not a good idea to use the name "xml" for the XHTML namespace. Names beginning with those three letters are reserved for special purposes by the XML specification. So it's probably a better idea to use a different name:

$xpc->registerNs( h => "http://www.w3.org/1999/xhtml" );
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: XML::LibXML and Namespace… I don't get it
by ikegami (Patriarch) on Jun 06, 2014 at 16:49 UTC
    From Namespaces in XML,

    The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace.

    The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/. It MUST NOT be declared . Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. Element names MUST NOT have the prefix xmlns.

    All other prefixes beginning with the three-letter sequence x, m, l, in any case combination, are reserved. This means that:

    • users SHOULD NOT use them except as defined by later specifications

    • processors MUST NOT treat them as fatal errors.

      Thanks for confirming and in fact this was one of my 2 mistaks.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re^2: XML::LibXML and Namespace… I don't get it
by Skeeve (Parson) on Jun 06, 2014 at 17:04 UTC

    Thanks! I already noticed the stuff about the dtd in place of the namespace. Stupid mistake.

    That stupid mistake interfered with the second one you pointed out and ikegami confirmed.

    So using the correct namespace and another prefix than "xml" solved the problem.

    Thanks a lot!


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e