gXML is an abstract XML interface that allows you to use multiple xml libraries through a common interface in Python.
TutorialInstalling gxml:
You can get gxml through easy_install:
easy_install gxml
Or you can download it directly from the cheeseshop:
http://pypi.python.org/pypi/gxml
Once you've done that, just extract the archive and run the standard.
python setup.py install Creating an element:
>>> from gxml import Element >>> node_a = gxml.Element('a') >>> node_a <a> >>> gxml.tostring(node_a) '<a />'
Adding and getting an attribute:
>>> node_a.set('this','that') >>> node_a.get('this') 'that' >>> gxml.tostring(node_a) '<a this="that" />'
Adding a child node:
>>> node_b = Element('b') >>> node_a.append(node_b) >>> gxml.tostring(node_a) '<a this="that"><b /></a>'
Setting a preferred backend:
Sometimes you'd just prefer if your code used a particular package.
>>> import gxml >>> gxml = gxml.preference('minidom') >>> gxml <module 'gxml.minidom' from 'gxml/minidom.py'>
>>> import gxml >>> gxml = gxml.preference('elementtree') >>> gxml <module 'gxml.elemtree' from 'gxml/elemtree.py'>
You can then access all the standard functions through the module.
>>> gxml.Element <function Element at 0xb19cb0> >>> gxml.tostring <function tostring at 0xb19cf0>
Getting the source:
The source can be found here, shoot me an email if you want to help out, or want something changed or added or whatever, I like feedback.
|