minidom
Peter Hansen
peter at engcorp.com
Tue Dec 4 10:20:58 EST 2001
Martin von Loewis wrote:
>
> 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.
Is it not required in any way at all? I always thought
it was.
> > >>> 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
Yes, this was not intended to be good style, or generally useful,
but merely an inspiration to the OP to use the interactive
console as a start in learning more about the API. I could
have made that clearer.
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list