Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: LibXML, XPath and Namespaces

by choroba (Canon)
on Mar 21, 2013 at 15:27 UTC ( #1024769=note: print w/ replies, xml ) Need Help??

in reply to LibXML, XPath and Namespaces

You can retrieve the namespace by the namespaceURI method:

my $doc = XML::LibXML->load_xml(location => '1.xml'); my $root = $doc->documentElement; my $nsuri = $root->namespaceURI;

You have to register the namespace before you can use it. It is annoying, but it is how XML works: if no namespace is specified, it means the empty namespace, not a default one (imagine the main:: package in Perl having no name).

If you find XML::LibXML too verbose (as I do), you might like XML::XSH2 which is a simple wrapper around it which reduces most of the incantations. Nevertheless, you still have to

register-namespace gt ;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Comment on Re: LibXML, XPath and Namespaces
Select or Download Code
Replies are listed 'Best First'.
Re^2: LibXML, XPath and Namespaces
by space_monk (Chaplain) on Mar 21, 2013 at 15:46 UTC
    Thanks very much,

    As you say I was really trying to find a way of getting round the verbosity. Unfortunately getting more libraries installed round here is awkward and quite time-consuming so I have to live with LibXML.

    A Monk aims to give answers to those who have none, and to learn from those who know more.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-11-26 07:40 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (696 votes), past polls