Link to home
Start Free TrialLog in
Avatar of CarlsbergFTW
CarlsbergFTWFlag for Romania

asked on

reformating XML , need to add nodes depending on one attribute id.

hello, i need to generate an xml file using data from a mysql database.

Aftger concatenating the tables + tags inside the select query i managed to create this kind of format:

<BEGIN>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 05:20:04" no="32"/>
<client  id="A1" title="A1 random x status" some_attribute="2011-05-03 18:00:03" no="32"/>
<client  id="A1" title="A1 r2 status" some_attribute="2011-05-03 05:30:01" no="32"/>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 19:00:02" no="32"/>
<client  id="B1" title="B1 000 status" some_attribute="2011-05-03 01:20:02" no="32"/>
<client  id="B1" title="B1 bla bla status" some_attribute="2011-05-03 13:20:03" no="32"/>
<client  id="C2" title="C2 xx status" some_attribute="2011-05-03 05:20:06" no="32"/>
<client  id="C2" title="C2 xoxoxo status" some_attribute="2011-05-0305:20:06" no="32"/>
</BEGIN>

Open in new window


What i need is a script or a way using mysql or some linux tool that can be automated (.pl .sh .whatever) to insert nodes depending on the id value found in the xml output i posted.

final output should be like this:
<BEGIN>
<A1>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 05:20:04" no="32"/>
<client  id="A1" title="A1 random x status" some_attribute="2011-05-03 18:00:03" no="32"/>
<client  id="A1" title="A1 r2 status" some_attribute="2011-05-03 05:30:01" no="32"/>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 19:00:02" no="32"/>\
</A1>
<B1>
<client  id="B1" title="B1 000 status" some_attribute="2011-05-03 01:20:02" no="32"/>
<client  id="B1" title="B1 bla bla status" some_attribute="2011-05-03 13:20:03" no="32"/>
</B1>
<C1>
<client  id="C2" title="C2 xx status" some_attribute="2011-05-03 05:20:06" no="32"/>
<client  id="C2" title="C2 xoxoxo status" some_attribute="2011-05-0305:20:06" no="32"/>
</C1>
</BEGIN>

Open in new window


Thank you experts!
Avatar of CarlsbergFTW
CarlsbergFTW
Flag of Romania image

ASKER

any input would be greatly appreciated.

Thank you!
This should be doable by awk.
ASKER CERTIFIED SOLUTION
Avatar of jackiechen858
jackiechen858
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the result is like:
<BEGIN>
<A1>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 05:20:04" no="32"/>
<client  id="A1" title="A1 random x status" some_attribute="2011-05-03 18:00:03" no="32"/>
<client  id="A1" title="A1 r2 status" some_attribute="2011-05-03 05:30:01" no="32"/>
<client  id="A1" title="A1 random status" some_attribute="2011-05-03 19:00:02" no="32"/>
</A1>
<B1>
<client  id="B1" title="B1 000 status" some_attribute="2011-05-03 01:20:02" no="32"/>
<client  id="B1" title="B1 bla bla status" some_attribute="2011-05-03 13:20:03" no="32"/>
</B1>
<C2>
<client  id="C2" title="C2 xx status" some_attribute="2011-05-03 05:20:06" no="32"/>
<client  id="C2" title="C2 xoxoxo status" some_attribute="2011-05-0305:20:06" no="32"/>
</C2>
</BEGIN>
Thank you for this imput. i will let you know about the result!
Thank you!