Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have an XML file with a structure like below.
<?xml version="1.0" encoding="UTF-8"?>
<data>
<loop>
<ID>135358</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
<loop>
<ID>135359</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
<loop>
<ID>135360</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
</data>
I would like this xml data to be saved as the following
file 1 = 135358.xml (with the data as shown below)
<data>
<loop>
<ID>135358</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
</data>
file 2 = 135359.xml (with the data as shown below)
<data>
<loop>
<ID>135359</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
</data>
file 3 = 135360.xml (with the data as shown below)
<data>
<loop>
<ID>135360</ID>
<MainData1>integer</MainData1>
<MainData2>string</MainData2>
<MainData3>string</MainData3>
<sub_loop1>
<looping_data>
<Data1>integer</Data1>
<Data2>string</Data2>
<Data3>string</Data3>
<Data4>float</Data4>
</looping_data>
</subloop1>
</loop>
</data>
If it's hard to name it using the <ID> field just a numeric count as filename is acceptable also.
Thanks in advance for your replies
Hi,
you can use a tExtractXMLFIeld with "data/loop" on Loop XPath query field , you set just one field on the component output type String :
and after you set the XPath query of the column to "."
you check GetNodes option
then you can add data tag like this "<data>" + your output string + "</data>" on a tjavarow or a tmap.
you can add this on a new field of the tjavarow or tmap :
(your input).replaceAll("(?s).*<ID>","").replaceAll("</ID>(?s).*","");
to get the value of ID
Send me Love and Kudos
Hello and thx for your time looking into my question.
As far as i can follow your explanation, this is to write out the ID field using (your input).replaceAll("(?s).*<ID>","").replaceAll("</ID>(?s).*",""); and the rest is preparation for this.
I also have been trying to split the file using advancedfileoutputxml but the closest i have gotten is 1 first file including the first record and then a second file was created but empty.
Maybe it's easier if i can make a test project and share it here so it's easier for everyone to see exactly how it is/should be done?
Will do this later today/tomorrow and attach it to this thread.
Textractxmlfield with the options i set in the first message let you split the xml data as you want, then add data tag before and After the string to get the xml structure you want. The replace function permit you to get the id of each loop, then you can do a tflowtoiterate and iterate on tfileoutputraw with your id as filename.
I'm getting a bit lost allrdy on the part to create 3 different xml from the basic xml file i have, it doesn't seem to add the data from the second loop the way i would like it to.
I added the project including the basic input and output file. hopefully u can guide me in the right way.
When u run this project u will see it doesn't add the data of the second loop.
Thanks allrdy for your time spend
Hi @not specified not specified :
Send me Love and kudos
Hi @not specified not specified , did you Succeed in your XML split ?
Send Me Love and Kudos
Hey, sorry for my late reply, changed the test to your setup but i don't seem to be able to put the same info in the trowgenerator see screenshot.
Hi, you have to set first the fields of the output schema of trowgenerator.
then you can fill them with the value you want.
Worked as requested, thank you very much!