XML ElementTree Parse.

marc.wyburn at googlemail.com marc.wyburn at googlemail.com
Thu Oct 12 06:03:05 EDT 2006


I'm playing with XML and elementtree and am missing something but I'm
not sure what...? I've create an XML file with Elementtree with a root
of backup.xml.  Attached to the root is a dirob and the dirobj has a
fileobj.  fileobj has filename and filesize tags.  I can open the file
in excel and it sets out the columns as I would expect.  The problem
I'm having is parsing the file. Using..

>>> file = open('c:\\scripts\\backup.xml', "r")
>>> tree = parse(file)
>>> elem = tree.getroot()
>>> elem.findtext('filesize')

Doesn't return anything, infact I can't seem to find anything
regardless of what I search for.
Here is the XML.  I've got a list of files and their containing
directories and I want my python script to append to the XML file each
day.  I could have done it with SQL but fancied banging my head on the
wall instead.  Thanks, MW.


- <backup.xml>
- <dirob>
  <dirname>C:\sysprep</dirname>
- <fileob>
  <filename>test.txt</filename>
  <filesize>10</filesize> 
  </fileob>
  </dirob>
  </backup.xml>




More information about the Python-list mailing list