XML line numbers

M

Martin DeMello

I'm using the REXML stream parser to read in an xml file and check the
attributes as I go. If a check fails, I want to print out the line
number in the XML file that contains the offending element - is that
possible?

e.g.

<foo>
<bar
baz="5" <--- should be between 1 and 3
quux="hello"
/>
</foo>

I want to print out "value of attribute 'baz' should be between 1 and 3
in line 3"

martin
 
S

Sean Russell

Martin DeMello said:
I'm using the REXML stream parser to read in an xml file and check the
attributes as I go. If a check fails, I want to print out the line
number in the XML file that contains the offending element - is that
possible?

Martin,

Check out Source#current_line. Line number support in REXML is
limited at the moment, since a "line" for REXML isn't something ending
in a "\n", but is something ending in ">". I've been considering ways
of counting "\n" lines without imposing a significant performance
penalty, but have had little luck.

--- SER
 
M

Martin DeMello

Sean Russell said:
Martin,

Check out Source#current_line. Line number support in REXML is
limited at the moment, since a "line" for REXML isn't something ending
in a "\n", but is something ending in ">". I've been considering ways
of counting "\n" lines without imposing a significant performance
penalty, but have had little luck.

Thanks - I'm going out of town for a few days, but I'll take a look at
it when I come back. This is a case where helpful error messages are
more useful than performance, so I don't mindf taking a bit of a speed
hit.

martin
 

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,149
Messages
2,570,843
Members
47,390
Latest member
RobertMart

Latest Threads

Top