[tt]Hi,
I trying to write a script in python to parse an xml file.
The xml file contains, measurements taken every 5 minutes. I need a script to parse the xml file and convert it to a csv formatted text.
Any help would highly appreciated :
example input file, i need to parse and take the values in the <measInfo measInfoId="TrafficMS">.
<measInfo measInfoId=" ControlCPM">
<granPeriod duration="PT300S" endTime="2013-12-06T10:40:37+01:00" />
<measType p="1">r5Ipv4Peers</measType>
<measType p="2">r5Ipv6Peers</measType>
<measType p="3">r8Ipv4Peers</measType>
<measType p="4">r8Ipv6Peers</measType>
<measType p="5">rxIpv4Peers</measType>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11">
<r p="1">3</r>
<r p="2">0</r>
<r p="3">0</r>
<r p="4">0</r>
<r p="5">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId=" ControlVP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:40:37+01:00" />
<measType p="1">ripUtilization</measType>
<measType p="2">numOfHssStaticSubscribersPerVprn</measType>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11,vprnRouterName=Base,vrId=1">
<r p="1">43.44</r>
<r p="2">0</r>
<suspect>false</suspect>
</measValue>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11,vprnRouterName=vprn765,vrId=5">
<r p="1">36.01</r>
<r p="2">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="SystemCP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">CpuUtilization</measType>
<measType p="2">MemoryUtilization</measType>
<measType p="3">ripv4SdfUtilization</measType>
<measType p="4">ripv6SdfUtilization</measType>
<measValue measObjLdn="KPI=System,GroupName=CP-ISA,group=1,slot=6,mda=1">
<r p="1">2</r>
<r p="2">28</r>
<r p="3">9.88</r>
<r p="4">0.00</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="ManagementCP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">Successful</measType>
<measType p="2">Failures</measType>
<measType p="3">FromNonSuccessful</measType>
<measType p="4">FromNonFailures</measType>
<measType p="5">WithPiggyBackingSuccessful</measType>
<measType p="6">mmProcedureSuccessful</measType>
<measValue measObjLdn="KPI=BearerManagement,GroupName=CP-ISA,group=1,slot=6,mda=1">
<r p="1">0</r>
<r p="2">0</r>
<r p="3">0</r>
<r p="4">0</r>
<r p="5">0</r>
<r p="6">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="TrafficMS">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">r5uGiUlPackets</measType>
<measType p="2">r5uGiUlBytes</measType>
<measType p="3">r5uGiUlDropPackets</measType>
<measType p="4">riS5uDlPackets</measType>
<measType p="5">riS5uDlBytes</measType>
<measType p="6">riS5uDlDropPackets</measType>
<measValue measObjLdn="KPI=BearerTraffic,GroupName=MSM,group=1,slot=6,mda=1">
<r p="1">9874210</r>
<r p="2">1527737770</r>
<r p="3">0</r>
<r p="4">11283018</r>
<r p="5">10144475091</r>
<r p="6">205558</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="SystemCPM">
<granPeriod duration="PT300S" endTime="2013-12-06T10:50:37+01:00" />
<measType p="1">CpuUtilization</measType>
<measType p="2">maxCpuUtilization</measType>
<measType p="3">MemoryUtilization</measType>
<measType p="4">maxMemoryUtilization</measType>
<measType p="5">priFlashUtilization</measType>
<measType p="6">recFlashUtilization</measType>
<measValue measObjLdn="KPI=System,GroupName=CPM,slot=11">
<r p="1">2</r>
<r p="2">3</r>
<r p="3">43</r>
<r p="4">43</r>
<r p="5">0</r>
<r p="6">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="TrafficMS">
<granPeriod duration="PT300S" endTime="2013-12-06T10:50:37+01:00" />
<measType p="1">r5uGiUlPackets</measType>
<measType p="2">r5uGiUlBytes</measType>
<measType p="3">r5uGiUlDropPackets</measType>
<measType p="4">riS5uDlPackets</measType>
<measType p="5">riS5uDlBytes</measType>
<measType p="6">riS5uDlDropPackets</measType>
<measValue measObjLdn="KPI=BearerTraffic,GroupName=MSM,group=1,slot=6,mda=1">
<r p="1">8874210</r>
<r p="2">2227737880</r>
<r p="3">0</r>
<r p="4">99283018</r>
<r p="5">33144475091</r>
<r p="6">445558</r>
<suspect>false</suspect>
</measValue>
</measInfo>
Output needed (csv):
output csv:
endtime,r5uGiUlPackets,r5uGiUlBytes,r5uGiUlDropPackets,riS5uDlPackets,riS5uDlBytes,riS5uDlDropPackets
2013-12-06T10:45:37+01:00,9874210,1527737770,0,11283018,10144475091,205558
2013-12-06T10:50:37+01:00,8874210,2227737880,0,99283018,33144475091,445558
I trying to write a script in python to parse an xml file.
The xml file contains, measurements taken every 5 minutes. I need a script to parse the xml file and convert it to a csv formatted text.
Any help would highly appreciated :
example input file, i need to parse and take the values in the <measInfo measInfoId="TrafficMS">.
<measInfo measInfoId=" ControlCPM">
<granPeriod duration="PT300S" endTime="2013-12-06T10:40:37+01:00" />
<measType p="1">r5Ipv4Peers</measType>
<measType p="2">r5Ipv6Peers</measType>
<measType p="3">r8Ipv4Peers</measType>
<measType p="4">r8Ipv6Peers</measType>
<measType p="5">rxIpv4Peers</measType>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11">
<r p="1">3</r>
<r p="2">0</r>
<r p="3">0</r>
<r p="4">0</r>
<r p="5">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId=" ControlVP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:40:37+01:00" />
<measType p="1">ripUtilization</measType>
<measType p="2">numOfHssStaticSubscribersPerVprn</measType>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11,vprnRouterName=Base,vrId=1">
<r p="1">43.44</r>
<r p="2">0</r>
<suspect>false</suspect>
</measValue>
<measValue measObjLdn="KCI=ControlPlane,GroupName=CPM,slot=11,vprnRouterName=vprn765,vrId=5">
<r p="1">36.01</r>
<r p="2">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="SystemCP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">CpuUtilization</measType>
<measType p="2">MemoryUtilization</measType>
<measType p="3">ripv4SdfUtilization</measType>
<measType p="4">ripv6SdfUtilization</measType>
<measValue measObjLdn="KPI=System,GroupName=CP-ISA,group=1,slot=6,mda=1">
<r p="1">2</r>
<r p="2">28</r>
<r p="3">9.88</r>
<r p="4">0.00</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="ManagementCP">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">Successful</measType>
<measType p="2">Failures</measType>
<measType p="3">FromNonSuccessful</measType>
<measType p="4">FromNonFailures</measType>
<measType p="5">WithPiggyBackingSuccessful</measType>
<measType p="6">mmProcedureSuccessful</measType>
<measValue measObjLdn="KPI=BearerManagement,GroupName=CP-ISA,group=1,slot=6,mda=1">
<r p="1">0</r>
<r p="2">0</r>
<r p="3">0</r>
<r p="4">0</r>
<r p="5">0</r>
<r p="6">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="TrafficMS">
<granPeriod duration="PT300S" endTime="2013-12-06T10:45:37+01:00" />
<measType p="1">r5uGiUlPackets</measType>
<measType p="2">r5uGiUlBytes</measType>
<measType p="3">r5uGiUlDropPackets</measType>
<measType p="4">riS5uDlPackets</measType>
<measType p="5">riS5uDlBytes</measType>
<measType p="6">riS5uDlDropPackets</measType>
<measValue measObjLdn="KPI=BearerTraffic,GroupName=MSM,group=1,slot=6,mda=1">
<r p="1">9874210</r>
<r p="2">1527737770</r>
<r p="3">0</r>
<r p="4">11283018</r>
<r p="5">10144475091</r>
<r p="6">205558</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="SystemCPM">
<granPeriod duration="PT300S" endTime="2013-12-06T10:50:37+01:00" />
<measType p="1">CpuUtilization</measType>
<measType p="2">maxCpuUtilization</measType>
<measType p="3">MemoryUtilization</measType>
<measType p="4">maxMemoryUtilization</measType>
<measType p="5">priFlashUtilization</measType>
<measType p="6">recFlashUtilization</measType>
<measValue measObjLdn="KPI=System,GroupName=CPM,slot=11">
<r p="1">2</r>
<r p="2">3</r>
<r p="3">43</r>
<r p="4">43</r>
<r p="5">0</r>
<r p="6">0</r>
<suspect>false</suspect>
</measValue>
</measInfo>
<measInfo measInfoId="TrafficMS">
<granPeriod duration="PT300S" endTime="2013-12-06T10:50:37+01:00" />
<measType p="1">r5uGiUlPackets</measType>
<measType p="2">r5uGiUlBytes</measType>
<measType p="3">r5uGiUlDropPackets</measType>
<measType p="4">riS5uDlPackets</measType>
<measType p="5">riS5uDlBytes</measType>
<measType p="6">riS5uDlDropPackets</measType>
<measValue measObjLdn="KPI=BearerTraffic,GroupName=MSM,group=1,slot=6,mda=1">
<r p="1">8874210</r>
<r p="2">2227737880</r>
<r p="3">0</r>
<r p="4">99283018</r>
<r p="5">33144475091</r>
<r p="6">445558</r>
<suspect>false</suspect>
</measValue>
</measInfo>
Output needed (csv):
output csv:
endtime,r5uGiUlPackets,r5uGiUlBytes,r5uGiUlDropPackets,riS5uDlPackets,riS5uDlBytes,riS5uDlDropPackets
2013-12-06T10:45:37+01:00,9874210,1527737770,0,11283018,10144475091,205558
2013-12-06T10:50:37+01:00,8874210,2227737880,0,99283018,33144475091,445558