User:Pluke/xml

From Wikibooks, open books for an open world
Jump to navigation Jump to search
  1. -------------------------------------------------------------------------------
  2. Name: module1
  3. Purpose:
  4. Author: pluke
  5. Created: 03/03/2013
  6. Copyright: (c) pluke 2013
  7. Licence: <your licence>
  8. -------------------------------------------------------------------------------
  1. tkinter drop downs
  2. http://effbot.org/tkinterbook/optionmenu.htm
  1. instructions on how to use xml functions
  2. http://docs.python.org/2/library/xml.etree.elementtree.html#building-xml-documents

def main():

   pass

if __name__ == '__main__':

   main()


import xml.etree.ElementTree as ET tree = ET.parse('c:/tmp/test.xml') root = tree.getroot()

  1. print root.tag
  1. print out each word

for child in root:

   print child.find('length').text
   print child.get('value')


  1. <?xml version="1.0"?>
  2. <dictionary>
  3. <word value="cat">
  4. <length>3</length>
  5. </word>
  6. <word value="dog">
  7. <length>11</length>
  8. </word>
  9. <word value="mouse">
  10. <length>2</length>
  11. </word>
  12. <word value="rat">
  13. <length>0</length>
  14. </word>
  15. </dictionary>