This is my xml file
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<outer1 xmlns="http://blablabla">
<inner1>
<name>Hello</name>
<org>wwf</org>
<profession>warrior</profession>
</inner1>
</outer1>
</config>
I want to do two things
- Get the attribute value from config and outer1
- Delete the attribute
This is the perl code
use strict;
use warnings;
use XML::LibXML;
my $xml = "Sample3.xml";
my $parser =XML::LibXML->new();
my $tree =$parser->parse_file($xml);
my $root =$tree->getDocumentElement;
print $root->getAttribute('xmlns:xc'), "\n";
print $root->getAttribute('/config/outer1/@xmlns'), "\n"; --> not working
$root->removeAttribute('xmlns:xc');--> not working
print "$tree->toString";
The output should be
<config>
<outer1>
<inner1>
<name>Hello</name>
<org>wwf</org>
<profession>warrior</profession>
</inner1>
</outer1>
</config>
I managed to get the value of xmlns:xc but not for xmlns. I tried the other way with $root->findvalue('/config/outer1/@xmlns');
but still not returning the value of xmlns. The other problem is removeAttribute. It doesn't recognize colon inside xmlns:xc but it does in getAttribute. I dont get why
Thanks in advance
In order to use namepsaces with XML::LibXML, use XML::LibXML::XPathContext: