xml.dom.minidom question

Uche Ogbuji uche at ogbuji.net
Wed Oct 8 10:04:11 EDT 2003


"Greg Krohn" <ask at me.com> wrote in message news:<2mjeb.10237$NX3.9179 at newsread3.news.pas.earthlink.net>...
> "Geiregat Jonas" <eniac at sdf-eu.org> wrote in message
> news:3f79ad4b$0$10696$ba620e4c at reader2.news.skynet.be...
> > I'm using xml.dom.minidom, I get some data by using
> > obj.getElementsByTagName("name")[0] then I have an object, but how can I
> > get the data between the tags ? I could do .toxml() and then strip it
> > away. But is there a better way maybe a function made for it ?
> > Also is it possible using the xml.dom.minidom module to create modify an
> > xml file ?
> 
> Given <name>Greg</name>, 'Greg' is considered an element inside the 'name'
> element. So, all you have to do is go one level of elements deeper.

You mean it's considered a text node inside of the 'name' element
node.

I'll point out that it might actually be more than one text node. 
Only safe way is to use the normalize() method.

Better yet, why torture yourself with DOM API, especially when all you
need is to extract data from XML files?

My recommendations would be to use Anobind, Elementtree,
gnosis.xml.objectify or 4XPath (an advanage of XPath is that at least
the extraction expression is ross-language):

Anobind:

http://uche.ogbuji.net/tech/4Suite/anobind/
http://www.xml.com/pub/a/2003/08/13/py-xml.html

Elementtree:

http://effbot.org/zone/element-index.htm
http://www.xml.com/pub/a/2003/02/12/py-xml.html

gnosis.xml.objectify:

http://www.xml.com/pub/a/2003/07/02/py-xml.html
http://www-106.ibm.com/developerworks/xml/library/x-matters11.html

4XPath:

http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/basic-xpath
http://www.xml.com/pub/a/2002/10/16/py-xml.html

Good luck.

--Uche
http://uche.ogbuji.net




More information about the Python-list mailing list