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

  1. get attribute value config , outer1
  2. 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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -