Dear fellow Monks,
I am in receipt of an xml message. What is the best way to retrieve the xmlns (namespace) attribute from the root element of that message using XML::LibXML??
If it helps, I am expecting GovTalkMessages of the format:
<!-- A valid Body payload with a namespace declaration on the first el
For bonus points, please tell me if there is any way of avoiding using XPathContext and adding the namespace identifier to all xpath queries on the resulting DOM.
e.g. do I really have to do:
my $dom = XML::LibXML->load_xml( string => $xml);
my $xc = XML::LibXML::XPathContext->new($dom);
$xc->registerNs( 'gt', 'http://www.govtalk.co.uk/CM/envelope');
$envelopeVersion = $xc->findvalue( '//gt:EnvelopeVersion');
A Monk aims to give answers to those who have none, and to learn from those who know more.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||