XMLObject - Easy Python Object interface to XML dataXMLObject does for XML data what SQLObject does for databases - it frees you of the cumbersome API normally used for manipulating XML files, and gives you a simple and much more Pythonic object interface.(This borrows some concepts from the xml_objectify.py, but adds the ability to save changes). Features
DownloadDownload your copy hereDocumentationView the epydoc-generated manualExampleBased on an xml file containing:
Here we go:
>>> from xmlobject import XMLFile# open up an existing XML file>>> x = XMLFile(path="sample.xml) >>> print x <xmlobject.XMLFile instance at 0xb7ccc52c># root node is in the .root attribute>>> print x.root <XMLNode: rapsheets># display contents of this node>>> print x.root._children [<XMLNode: text>, <XMLNode: person>, <XMLNode: text>, <XMLNode: person>, <XMLNode: text>]# access only <person...> nodes>>> print x.root.person [<XMLNode: person>, <XMLNode: person>]# Easily access the node's tag attributes>>> print x.root.person[0].name John Smith# get a ref to the first <person> node>>> john = x.root.person[0]# Easy to change existing attributes, or set new ones>>> john.height = 184# Also easy to insert sub-nodes (and text nodes, and comments) |