in reply to Re: xmlns and XML::LibXML
in thread xmlns and XML::LibXML

I cannot see how to use. XML::LibXML::XPathContext

The man page says:

registerNs $xpc->registerNs($prefix, $namespace_uri) Registers namespace $prefix to $namespace_uri.

But I do not know in advance what the prefix will be.

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

Is valid and

<?xml version="1.0" encoding="utf-8" ?> <D:propfind xmlns:D="DAV:"> <D:prop xmlns:R="http://ns.example.com/boxschema/"> <R:bigbox/> <R:author/> <R:DingALing/> <R:Random/> </D:prop> </D:propfind>

is valid too.

Worik

Replies are listed 'Best First'.
Re^3: xmlns and XML::LibXML
by Anonymous Monk on Jun 02, 2015 at 03:33 UTC

    But I do not know in advance what the prefix will be.

    You don't need to know it, a prefix is for your xpaths, the namespace is important not the prefix, the prefix is just a shortcut for the namespace

    The person writing xml "registers" a local prefix so they can write their XML with less chars

    The person writing xpath "registers" a local prefix so they can write their xpath with less chars

    Neither person has to use the same prefix to refer to the same namespace

Re^3: xmlns and XML::LibXML
by ikegami (Patriarch) on Jun 02, 2015 at 13:11 UTC
    The prefix used in the XPath doesn't have to match the prefix used in the document. Only the namespaces need to match. Pick a prefix of your liking. See Re^2: xmlns and XML::LibXML.
Re^3: xmlns and XML::LibXML
by Anonymous Monk on Jun 02, 2015 at 09:28 UTC
    I cannot see how to use. XML::LibXML::XPathContext

    Please read the replies carefully. A working piece of example code was given to you an hour before you posted this.