mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-07 03:16:41 +00:00
763 B
763 B
XML Module CheatSheet
Submodules
The XML handling submodules are:
xml.etree.ElementTree
: the ElementTree API, a simple and lightweight XML processorxml.dom
: the DOM API definitionxml.dom.minidom
: a minimal DOM implementationxml.dom.pulldom
: support for building partial DOM treesxml.sax
: SAX2 base classes and convenience functionsxml.parsers.expat
: the Expat parser binding
xml.etree.ElementTree
import xml.etree.ElementTree as ET
data = "<xml/>"
tree = ET.fromstring(data) # parse string containing XML
tree.find("tag").text # return data contained between <tag></tag>
tree.find("tag").get("attribute") # return value of <tag attrubute="value">
tree.findall("tag1/tag2") # list of tag2 inside tag1