Plain old SAX and minidom useable? But how then?
Carsten Haese
carsten at uniqsys.com
Wed Aug 1 08:19:41 EDT 2007
On Wed, 2007-08-01 at 04:58 -0700, Dobedani wrote:
> [...]
> "Nelson says: There's the stock Python install, which barely does
> anything [for XML]. That's overstated. Plain old SAX and minidom may
> not be ideal, but they're useable."
>
> Please: where then can I find examples of such use? If I cannot use
> xpath, I would not mind to browse a bit - e.g. using functions like
> getElementByTag() but I don't even know how to use those. TIA
Here's a micro-tutorial:
>>> import xml.dom.minidom
>>> contents = """\
... <root>
... <thing>Parrot</thing>
... <thing class="special">Holy Grail</thing>
... </root>"""
>>> dom = xml.dom.minidom.parseString(contents)
>>> things = dom.getElementsByTagName("thing")
>>> print things[0].childNodes
[<DOM Text node "Parrot">]
>>> print things[0].childNodes[0].nodeValue
Parrot
>>> print things[0].hasAttribute("class")
False
>>> print things[0].getAttribute("class")
>>> print things[1].childNodes
[<DOM Text node "Holy Grail">]
>>> print things[1].childNodes[0].nodeValue
Holy Grail
>>> print things[1].hasAttribute("class")
True
>>> print things[1].getAttribute("class")
special
There's also the online documentation at
http://docs.python.org/lib/module-xml.dom.minidom.html
Hope this helps,
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list