gurudasha
asked on
To delete and replace and xml element using XML::Twig
I have a requirement to replace and xml element
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<JavaHost>
.............
..........
<ABC>
<InputStreamLimitInKB>5625 </InputStr eamLimitIn KB>
<ReadRequestBeforeProcessi ng>true</R eadRequest BeforeProc essing>
</ABC>
....
...
</javahost>
If InputStreamLimitInKB is 5625 i have to change it to 3268
The xml file should get updated.
Please help as i am new to xml twig
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<JavaHost>
.............
..........
<ABC>
<InputStreamLimitInKB>5625
<ReadRequestBeforeProcessi
</ABC>
....
...
</javahost>
If InputStreamLimitInKB is 5625 i have to change it to 3268
The xml file should get updated.
Please help as i am new to xml twig
The problem with suhasbharadwaj's answer is that it is non-specific. If 5625 occurs anywhere in the file (even as part of another number), it will replace it. I would recommend this instead:
You can also do the above as part of another script using a loop. If you want to replace it in-place in the file, I'd suggest Tie::File if you want it as part of another script.
I can not give you an XML::Twig answer as I use other XML modules.
perl -pi -e 's{<InputStreamLimitInKB>5625</InputStreamLimitInKB>}{<InputStreamLimitInKB>3268</InputStreamLimitInKB>}gi' file.xml
If the XML is structured such that the tags will ever not be on the same line as the value for InputStreamLimitInKB, then the above will need to be tweaked.You can also do the above as part of another script using a loop. If you want to replace it in-place in the file, I'd suggest Tie::File if you want it as part of another script.
foreach (<INPUT>) {
s{<InputStreamLimitInKB>5625</InputStreamLimitInKB>}{<InputStreamLimitInKB>3268</InputStreamLimitInKB>}gi;
}
I can not give you an XML::Twig answer as I use other XML modules.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because i used the module i was asking for
perl -pi -e 's/5625/3268/g' file.xml