minidom help -- line number

G

GZ

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.

Can anyone give me some help?

Thanks,
gz
 
T

Thomas Jollans

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.
 
G

GZ

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.

So I am basically out of luck if I want to tie back to the original
file for file error reporting etc. sounds like a deficiency to me.
 
T

Thomas Jollans

So I am basically out of luck if I want to tie back to the original
file for file error reporting etc. sounds like a deficiency to me.

The DOM is disjunct from the original file, stream, string, etc. That's in the
nature of the DOM, and it's probably true for most, if not all, DOM
implementations, in other programming languages as well as Python.
If you want to stay close to the file, you're better of with SAX. (or a
similar approach, like eXpat)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top