I need to create a bash script that manipulates the following sample xml file:
- check for a particular ID and remove that XML branch for that ID.
the ID's are read from a text file.
<?xml version="1.0"?> <cmtf xmlns="urn:RM_UPMS_CMTFEnvelopeSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <data xmlns=""> <entitygroup entityname="people"> <PERSON xmlns="abc"> <ID ns="">12280</ID> <PIN xmlns="">erererre</PIN> <NAME xmlns="">ereffdef</NAME> </PERSON> <PERSON xmlns="bbc"> <ID ns="">5567</ID> <PIN xmlns="">erererre</PIN> <NAME xmlns="">ereffdef</NAME> </PERSON> <PERSON xmlns="bbc"> <ID ns="">3347</ID> <PIN xmlns="">ededed</PIN> <NAME xmlns="">rtreer</NAME> </PERSON> <PERSON xmlns="bbc"> <ID ns="">3249</ID> <PIN xmlns="">erererre</PIN> <NAME xmlns="">ereffdef</NAME> </PERSON> </entitygroup> </data> </cmtf>
Here, I need to remove all the <PERSON> tag for all the entries that have the ID 12280, 3249 which is being read from a text file.
xml-sed, part ofxml-coreutilsmay be your friend to perform simple operations on XML files.