I want to change an XML attribute value using XML::Twig
. I can do this by using XML::LibXML
like this
my $doc = XML::LibXML->new->parsefile();
my $xpath = '/model/@name';
my ($attr) = $doc->findnodes($xpath);
$attr->setValue('dfdsa');
But I have to used XML::Twig
because of some constraints
input
<model name="XXXX" oid="i">
<system oid="1" uri="/gaia" listing="NO">
<schema desc="HTTP Sever schema" enab="YES" name="HTTP" oid="1" prio="5">
</schema>
</system>
</model>
output
<model name="dfdsa" oid="i">
<system oid="1" uri="/gaia" listing="NO">
<schema desc="HTTP Sever schema" enab="YES" name="HTTP" oid="1" prio="5">
</schema>
</system>
</model>
I tried this code but it's not modifying the content
my $doc = XML::Twig->new->parsefile('pattern.xml');
my $xpath = '/model';
my ($attr) = $doc->findnodes($xpath);
$attr->set_att(name => 'dfdsa');