Elementtree use cases


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.