Até agora eu fiz coisas simples no bash com sed, awk, while loops, etc.
O que eu preciso fazer agora é muito mais complicado e não sei como começar.
Eu tenho um arquivo XML e preciso adicionar elemento (s) a ele com base nas outras informações no arquivo XML.
Quais ferramentas devo usar para realizar isso? while loops , arrays , sed ?
Obtenha uma lista dos IDs compostos e armazene-os em uma matriz
Para cada ID composta, pesquise todos os IDs individuais que correspondem ao ID composto e armazene os resultados de cada ID individual em uma matriz.
a. Se algum dos IDs individuais tiver uma tag positiva, crie um novo no arquivo XML e defina o como positivo.
b. Se todos os IDs individuais tiverem uma tag negativa, crie um novo no arquivo XML e defina o como negativo.
Por exemplo, este é um exemplo de como seria o arquivo XML original:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<waterSample>
<HeaderInformation>
<ReportSerialNumber>987754</ReportSerialNumber>
</HeaderInformation>
<sample>
<site>40</site>
<sampleid>040-2016-12387</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid></compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-001</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Negative</result>
<units>10oz</units>
</sample>
<sample>
<site>40</site>
<sampleid>040-2016-12388</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid>78979</compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-002</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Negative</result>
<units>10oz</units>
</sample>
<sample>
<site>40</site>
<sampleid>040-2016-12389</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid>78979</compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-003</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Positive</result>
<units>10oz</units>
</sample>
</waterSample>
Isto é o que o arquivo ficaria depois que o código fosse executado:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<waterSample>
<HeaderInformation>
<ReportSerialNumber>987754</ReportSerialNumber>
</HeaderInformation>
<sample>
<site>40</site>
<sampleid>040-2016-12387</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid></compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-001</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Negative</result>
<units>10oz</units>
</sample>
<sample>
<site>40</site>
<sampleid>040-2016-12388</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid>78979</compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-002</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Negative</result>
<units>10oz</units>
</sample>
<sample>
<site>40</site>
<sampleid>040-2016-12389</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid>78979</compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid>789-879717-003</labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Positive</result>
<units>10oz</units>
</sample>
<sample>
<site>40</site>
<sampleid>040-2016-78979</sampleid>
<productcode>AQUA</productcode>
<productdescription>10ozAquafina</productdescription>
<testcode>Oxygen</testcode>
<testdescription>Test for Oxygen</testdescription>
<sequence>0</sequence>
<sampledate>2016-05-27T16:03:00-05:00</sampledate>
<prefix></prefix>
<addendum></addendum>
<compositeid></compositeid>
<samplename>Water</samplename>
<sampledescription>Tasty Water</sampledescription>
<labsampleid></labsampleid>
<receivedby>John Doe</receivedby>
<receivetime>2016-05-28T10:49:43-04:00</receivetime>
<reporttime>2016-05-30T11:30:11-04:00</reporttime>
<result>Positive</result>
<units>10oz</units>
</sample>
</waterSample>