Posted By

manatlan on 09/09/09


Tagged

python xml etree


Versions (?)

Elementtree use cases


 / Published in: Python
 

  1. #from elementtree.etree importe ElementTree
  2. from xml.etree import ElementTree
  3.  
  4. #a=ElementTree.parse("toto.xml")
  5. a=ElementTree.fromstring("<a>fds</a>")
  6.  
  7. b=ElementTree.XML("<b/>")
  8. a.append(b)
  9.  
  10. b=ElementTree.Element("b",{"key":"value"})
  11. b.text = "kiki"
  12. b.set("toto","tata")
  13. a.append(b)
  14.  
  15.  
  16. print ElementTree.tostring(a,encoding="Windows-1252")
  17.  
  18. for i in a.findall("b"):
  19. print i,i.get("key")

Report this snippet  

You need to login to post a comment.