On Sun, 21 Jun 2015 16:56:27 -0700, Sahlusar wrote:

> Here is an example XML document that I am working with:

> You are welcome to contribute and provide me with feedback. Thank you
> for your continued feedback and guidance.

Your XML is invalid! You have a closing MO tag with no opening tag.

> This is the output that I seek:

> > "a","b"   // headers 
> > "b",1     // data row 1 
> > "b",2     // data row 2

I assume from this that where you have a list of identical elements at 
the deepest nesting level of the XML file, you require one CSV record for 
each element in that list, and that you want all higher level element 
values and attributes duplicated in each CSV record.

I assume that you want to use the tag name of each element as the 
identifier for the text content of the element (where there is any), and 
that where an element has no text content, a 0 value is appropriate.

I also assume that as long as the relationship between the headers and 
the data is correct, it does not matter what order the headers are in, ie 
the data and headers can both be sorted by the header.

The output of my code generated once I had corrected your broken XML by 
inserting an 'MO' opening tag between the 'Response' opening tag and the 
'MonthDayCount' opening tag can be seen at:

http://www.sined.co.uk/tmp/xml_to_csv.txt

This was generated from xml file:

http://www.sined.co.uk/tmp/xml_data.txt

If you want the code that produced it, we can discuss fees, it took a few 
hours and for consultancy like this I expect a few 10s of $ per hour.

There may be a generic method to do what you want involving parsing the 
xml to a nested dictionary / list data object, and then flattening that 
object, but I don't see that generating you one line of CSV for each 
Int32 in MonthDayCount.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to