Generate XML From a CSV or TXT File
Posted: 19 Dec 2017 16:07
Hello DOSTips list
I have been looking into how to create an XML file from a CSV or TXT (source.csv), and while I can now successfully echo the required syntax to create an XML (output.xml) manually.
However, to take it to the next level, we need to be able to read from a CSV or TXT (source.csv) file with six comma-separated values per line and read from the CSV or TXT (output.xml) file as source material for how to populate the generated XML (output.xml) file.
The source CSV or TXT (source.csv) file has many lines, each with the following types of data:
date,source,title,type,value,description
So an example from a CSV or TXT (source.csv) file:
12-19-2017, New York Times, Salad Spinners Observed Chasing Unicorns, open sources, lorem ipsum, flotsam and jetsam
12-15-2017, Washington Post, Salad Spinners Observed Chasing Unicorns, interview, eleven past five, The sister of an only child baked a marmite pizza
And we hope to have it create an XML (output.xml) file:
<stix:Timestamp:>12-19-2017</stix:Timestamp>
<indicator:Source:>New York Times</indicator:Source>
<indicator:Title:>Salad Spinners Observed Chasing Unicorns</indicator:Title>
<indicator:Type:>open sources</indicator:Type>
<indicator:Value:>lorem ipsum</indicator:Value>
<indicator:Description:>flotsam and jetsam</indicator:Description>
<stix:Timestamp:>12-15-2017</stix:Timestamp>
<indicator:Source:>Washington Post</indicator:Source>
<indicator:Title:>Salad Spinners Observed Chasing Unicorns</indicator:Title>
<indicator:Type:>interview</indicator:Type>
<indicator:Value:>eleven past five</indicator:Value>
<indicator:Description:>The sister of an only child baked a marmite pizza</indicator:Description>
thank you in advance - I hope I have described this clearly
I have been looking into how to create an XML file from a CSV or TXT (source.csv), and while I can now successfully echo the required syntax to create an XML (output.xml) manually.
However, to take it to the next level, we need to be able to read from a CSV or TXT (source.csv) file with six comma-separated values per line and read from the CSV or TXT (output.xml) file as source material for how to populate the generated XML (output.xml) file.
The source CSV or TXT (source.csv) file has many lines, each with the following types of data:
date,source,title,type,value,description
So an example from a CSV or TXT (source.csv) file:
12-19-2017, New York Times, Salad Spinners Observed Chasing Unicorns, open sources, lorem ipsum, flotsam and jetsam
12-15-2017, Washington Post, Salad Spinners Observed Chasing Unicorns, interview, eleven past five, The sister of an only child baked a marmite pizza
And we hope to have it create an XML (output.xml) file:
<stix:Timestamp:>12-19-2017</stix:Timestamp>
<indicator:Source:>New York Times</indicator:Source>
<indicator:Title:>Salad Spinners Observed Chasing Unicorns</indicator:Title>
<indicator:Type:>open sources</indicator:Type>
<indicator:Value:>lorem ipsum</indicator:Value>
<indicator:Description:>flotsam and jetsam</indicator:Description>
<stix:Timestamp:>12-15-2017</stix:Timestamp>
<indicator:Source:>Washington Post</indicator:Source>
<indicator:Title:>Salad Spinners Observed Chasing Unicorns</indicator:Title>
<indicator:Type:>interview</indicator:Type>
<indicator:Value:>eleven past five</indicator:Value>
<indicator:Description:>The sister of an only child baked a marmite pizza</indicator:Description>
thank you in advance - I hope I have described this clearly