[Tutor] Newbie to Python: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)
Alan Gauld
alan.gauld at btinternet.com
Fri Jun 26 00:51:16 CEST 2015
On 25/06/15 19:42, Saran Ahluwalia wrote:
> My question can be found here:
>
> http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python
It would have been helpful to post the question here rather than just a
link.
However, having read it, I'm still not sure what you want to do?
It seems your input file (the XML one?) has multiple ObjectGuid tags?
And you want to write them out to a CSV file with a number appended
(objectGuid_1, ObjectGuid_2 etc) Is that right? If so what exactly is
the issue - it seems simple enough (given your obvious coding
experience) to store a counter and create a new string each time you
find a GUID tag?
But I still don't understand how these tags relate to the rest of the
data in the file? Are you only extracting the GUID and want one row per
file? Or are you extracting multiple data structures and creating a row
for each? In which case are the multiple GUID embedded in each data
structure? I'm really not sure what you are trying to do.
> Here is an additional sample sample of the XML that I am working with:
I have no idea how that is supposed to help? It doesn't have any
ObjectGUID tags that I can see? It is essentially meaningless
data (to us).
>
> <Response ID="123546 - 7831" RequestType="Moverview">
> <MonthDayCount>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> </MonthDayCount>
> <FeeCount>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> <Int32>0</Int32>
> </FeeCount>
> <PaymentBucketAmount>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> <Double>0</Double>
> </PaymentBucketAmount>
> <PaymentBucketDueDate>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> <DateTime>1/1/0001 12:00:00 AM</DateTime>
> </PaymentBucketDueDate>
> <Warnings />
> <SList />
> <LList />
> <PA>False</PA>
> <PL>False</PL>
> <PC>False</PC>
> <PCs>False</PCs>
> <PJ>False</PJ>
> <OITC>0</OITC>
> <MG />
> <R />
> <CCGoods />
> </Response>
> --
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list