xml.dom.minidom question

Stefan Behnel stefan_ml at behnel.de
Sun Nov 20 10:03:24 EST 2011


nivashno, 19.11.2011 22:32:
> I've got this code:
>
> >>> dom = xml.dom.minidom.parse('myfile.xml')
> >>> for testnode in dom.getElementsByTagName('tests')[0].childNodes:
> ...     print testnode
>
> When it's working on this xml:
>
>      <tests>
>        <test>something</test>
>      </tests>
>
> I get the following:
>
> <DOM Text node "u'\n      '">
> <DOM Element: test at 0xaa6bfac>
> <DOM Text node "u'\n    '">
>
> But when it's working on this xml:
>
>      <tests><test>something</test></tests>
>
> I get this:
>
> <DOM Element: test at 0xbc6f1ac>
>
>
> I always thought that xml was very precisely split up into nodes,
> childnodes, etc, no matter what the whitespace between them was. But
> apparently not, or am I missing something?

You already got some answers to this question. I'd just like to point you 
to the xml.etree.(c)ElementTree packages, which are substantially faster 
and easier to use than minidom.

Stefan




More information about the Python-list mailing list