I have a script that curl a command to sms gateway to send sms and get xml as response. Each response are appended to a single file for future xsltproc process for creating csv.
A single response is like:
<?xml version='1.0' encoding='ISO-8859-1' ?><REPLY><PARAMETER>OK</PARAMETER><LOGIN>SUCCESSFULL</LOGIN><PUSHAPI>ACTIVE</PUSHAPI><STAKEHOLDERID>OK</STAKEHOLDERID><PERMITTED>OK</PERMITTED><SMSINFO><MSISDN>xxxxxxxxxxxxx</MSISDN><SMSTEXT>Test+SMS+Check</SMSTEXT><CSMSID>113426778</CSMSID><REFERENCEID>2020050321383271896124009</REFERENCEID></SMSINFO></REPLY>
Now each time the script runs it appends the same response with separate values with duplicate <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
and </REPLY>
so after 2nd time execution the file will be:
<?xml version='1.0' encoding='ISO-8859-1' ?><REPLY><PARAMETER>OK</PARAMETER><LOGIN>SUCCESSFULL</LOGIN><PUSHAPI>ACTIVE</PUSHAPI><STAKEHOLDERID>OK</STAKEHOLDERID><PERMITTED>OK</PERMITTED><SMSINFO><MSISDN>xxxxxxxxxxxxx</MSISDN><SMSTEXT>Test+SMS+Check</SMSTEXT><CSMSID>113426778</CSMSID><REFERENCEID>2020050321383271896124009</REFERENCEID></SMSINFO></REPLY><?xml version='1.0' encoding='ISO-8859-1' ?><REPLY><PARAMETER>OK</PARAMETER><LOGIN>SUCCESSFULL</LOGIN><PUSHAPI>ACTIVE</PUSHAPI><STAKEHOLDERID>OK</STAKEHOLDERID><PERMITTED>OK</PERMITTED><SMSINFO><MSISDN>xxxxxxxxxxxxx</MSISDN><SMSTEXT>Test+SMS+Check</SMSTEXT><CSMSID>113426778</CSMSID><REFERENCEID>2020050321383271896124009</REFERENCEID></SMSINFO></REPLY>
which have 2 <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
and </REPLY>
.
But xsltproc can not process multiple <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
and </REPLY>
So I need to remove all <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
and </REPLY>
and just keep or add a <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
at beginning of file and </REPLY>
end of file while final processing.
So my file while processing for xsltproc after 2nd run should be like:
<?xml version='1.0' encoding='ISO-8859-1' ?><REPLY><PARAMETER>OK</PARAMETER><LOGIN>SUCCESSFULL</LOGIN><PUSHAPI>ACTIVE</PUSHAPI><STAKEHOLDERID>OK</STAKEHOLDERID><PERMITTED>OK</PERMITTED><SMSINFO><MSISDN>xxxxxxxxxxxxx</MSISDN><SMSTEXT>Test+SMS+Check</SMSTEXT><CSMSID>113426778</CSMSID><REFERENCEID>2020050321383271896124009</REFERENCEID></SMSINFO><PARAMETER>OK</PARAMETER><LOGIN>SUCCESSFULL</LOGIN><PUSHAPI>ACTIVE</PUSHAPI><STAKEHOLDERID>OK</STAKEHOLDERID><PERMITTED>OK</PERMITTED><SMSINFO><MSISDN>xxxxxxxxxxxxx</MSISDN><SMSTEXT>Test+SMS+Check</SMSTEXT><CSMSID>113426778</CSMSID><REFERENCEID>2020050321383271896124009</REFERENCEID></SMSINFO></REPLY>
So how to remove all <?xml version='1.0' encoding='ISO-8859-1' ?><REPLY>
except the first one in the file and remove all </REPLY>
except the last one.
Or is there any other way to create the csv or xlx for record.