in reply to Extract a string from the line
use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => 'file.xml'); my $digits = $dom->findvalue('//stlib:mem_bit'); print $digits, "\n";
To do it correctly, you should register the namespace, but you haven't provided its definition, so I can't show you exactly how to do it. Let's say the whole XML file look like this:
<r xmlns:stlib="http://stlib.xml.ns"> <ch> <stlib:mem_bit>72</stlib:mem_bit> </ch> </r>
The correct XML namespace handling code would be
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => '1.xml'); my $xpc = 'XML::LibXML::XPathContext'->new; $xpc->registerNs(s => 'http://stlib.xml.ns'); my $digits = $xpc->findvalue('//s:mem_bit', $dom); print $digits, "\n"
|
|---|