Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: xmlns and XML::LibXML

by worik (Sexton)
on Jun 02, 2015 at 03:28 UTC ( [id://1128694]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128694]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found