I have the below XML file that need to be converted to csv with "value" fields only. there are a few hundred possibilities that are different for each XML type/version.
I've tried using below code in python3 and getting error as "AttributeError: 'NoneType' object has no attribute 'text'".
import pandas as pd
import xml.etree.ElementTree as et
xtree = et.parse("data.xml")
xroot = xtree.getroot()
output=[]
for node in xroot:
v = node.find("value").text
output.append(v);
out_df = pd.DataFrame(output, columns = ["value"])
out_df.to_csv('output.csv')
my data.xml input is as below
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record source="AJS/SHD" type="call">
<group name="General">
<field name="RecordType" value="RESGJG"/>
<field name="RecordTypeHEC" value="PY"/>
<field name="NodeID" value="rock.dsjjgds.cm"/>
<field name="SequenceNumber" value="7937973"/>
<field name="StartDate" value="20171049979"/>
<field name="EndDate" value="201704059739793"/>
<field name="CallDuration" value="973979i"/>
<field name="CauseForRecordClosing" value="normal"/>
</group>
<group name="SIP">
<field name="ICID" value="dshhkdhs"/>
<field name="CallID" value="sdidydakyd2133@10.10.10.1"/>
<field name="User-Agent" value="NotPresent"/>
<field name="Request-URI" value="sip:+47668384"/>
<field name="CalledPartyNumber" value="sip:+08779379972"/>
<field name="CallingPartyNumber" value="sip:+07073873772@10.0.0.1"/>
<field name="To" value="sip:+878379739"/>
<field name="From" value="sip:+937973962"/>
</group>
<group name="VPN">
<field name="VPN_NAME_B" value="blshahd"/>
<field name="VPN_Group_B" value="ctr"/>
<field name="B_ExtType" value="part"/>
<field name="B_ISDN" value="7973"/>
<field name="B_SIP" value="67367672"/>
<field name="B_PABXID" value="797397"/>
</group>
</record>
</records>
expected output is to export all "value" to csv file below.
RESGJG,PY,rock.dsjjgds.cm,7937973,20171049979,201704059739793,973979i,normal,dshhkdhs,sdidydakyd2133@10.10.10.1,NotPresent,sip:+47668384,sip:+08779379972,sip:+07073873772@10.0.0.1,sip:+878379739,sip:+937973962,blshahd,ctr,part,7973,67367672,797397
Please help, i have tried various python references, but no luck.