Tom_Good1 at excite.com
Wed Dec 5 01:53:14 CET 2001
Peter Hansen <peter at engcorp.com> wrote in message news:<3C0CE9DA.128BBF4A at engcorp.com>...
> 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').childNodes.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.
Maybe something like this could be used to be more general...
e = doc.getElementsByTagName('DESCRIPTION')
alltext = [a.nodeValue for a in e.childNodes if a.nodeType == a.TEXT_NODE]
More information about the Python-list