xml - LibXML : colon in removeAttribute and value in getAttribute -
this 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 2 things
- get attribute value config , outer1
- delete attribute
this perl code
use strict; use warnings; use xml::libxml; $xml = "sample3.xml"; $parser =xml::libxml->new(); $tree =$parser->parse_file($xml); $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 value of xmlns:xc not xmlns. tried other way $root->findvalue('/config/outer1/@xmlns');
still not returning value of xmlns. other problem removeattribute. doesn't recognize colon inside xmlns:xc in getattribute. dont why
thanks in advance
in order use namepsaces xml::libxml, use xml::libxml::xpathcontext:
#!/usr/bin/perl use warnings; use strict; use feature qw{ }; use xml::libxml; $xml = 'xml::libxml'->load_xml( string => '<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>'); $xpc = 'xml::libxml::xpathcontext'->new; $xpc->registerns('b', 'http://blablabla'); $xpc->findnodes('/config/b:outer1', $xml); # ^^^
Comments
Post a Comment