minidom

Martin von Loewis loewis at informatik.hu-berlin.de
Tue Dec 4 09:59:36 EST 2001


Peter Hansen <peter at engcorp.com> writes:

> For one, you should probably start your XML document with 
> <?xml version="1.0"?> or it won't be valid XML (but that's
> not necessary for this case.)  

That is not true. Presence of the XML declaration is not a validity
constraint in XML.

> >>> from xml.dom import minidom
> >>> doc = minidom.parseString(open('test.xml').read())
> >>> doc.getElementsByTagName('DESCRIPTION')[0].childNodes[0].nodeValue
> u'EngineStart Leak'

Actually, obtaining the text by looking at the first child is
unreliable: The first child may be a comment, and the text may be
split over several nodes, unless .normalize() was called (in which
case the text can still be split over several notes, in case of
comments, CDATA sections, or processing instructions).

Regards,
Martin




More information about the Python-list mailing list