python and xml

Stefan Behnel stefan_ml at behnel.de
Wed May 16 10:23:34 EDT 2012


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))


Stefan




More information about the Python-list mailing list