python and xml
Stefan Behnel
stefan_ml at behnel.de
Wed May 16 10:36:03 EDT 2012
Hi,
please don't top-post (I fixed the citation order below).
Nibin V M, 16.05.2012 16:30:
> On Wed, May 16, 2012 at 7:53 PM, Stefan Behnel wrote:
>> Nibin V M, 16.05.2012 16:16:
>>> I am trying to use cPanel XML-API and every API call return data in XML
>>> format. I would like to know how to manipulate the data here.
>>>
>>> For eg: How can I read the CPU load data from the below output
>>>
>>>
>>>
>> <loadavg><one>0.00</one><five>0.00</five><fifteen>0.00</fifteen>
>> </loadavg><!-- whostmgrd -->
>>
>> Here's some untested code to print the text values:
>>
>> import xml.etree.ElementTree as ET
>>
>> loadavg = ET.fromstring('<loadavg><one>0.00</one><five>0.00</five>'
>> '<fifteen>0.00</fifteen></loadavg>')
>>
>> for interval_tag in ('one', 'five', 'fifteen'):
>> print(loadavg.findtext(interval_tag))
>
> thank you Stefan. but the XML output is assigned to a variable; how to
> process the variable with XML contents?
Not sure what you mean. Maybe something like this?
xml = '<loadavg><one>0.00</one><five>0.00</five>...</loadavg>'
loadavg = ET.fromstring(xml)
Stefan
More information about the Python-list
mailing list