minidom help -- line number

Thomas Jollans thomas at jollybox.de
Sat Aug 14 19:07:49 CEST 2010


On Saturday 14 August 2010, it occurred to GZ to exclaim:
> Hi All,
> 
> I am writing a little program that reads the minidom tree built from
> an xml file. I would like to print out the line number of the xml file
> on the parts of the tree that are not valid. But I do not seem to find
> a way to correspond minidom nodes to line numbers.

The DOM does not contain things like line number information. You work with 
the structure of the document, not the appearance of the file you happen to be 
using as a source. You can't use line numbers with minidom.

For stream-based parsers like SAX and eXpat (both in the standard library) 
this makes more sense, and they both allow you to check the current line 
number in one way or another.





More information about the Python-list mailing list