Re: java get xml file line number for the current node
On 02/20/2012 01:35 PM, Gene Wirchenko wrote:
On Mon, 20 Feb 2012 11:58:34 -0800, Lew<noone@lewscanon.com> wrote:
mani wrote:
How can I now find the line number in the source XML file where this
node occurs?
It's a meaningless question. There are no line numbers in XML.
Really, Lew!
There are no line numbers in Java either, but somehow,
compilation messages that give line numbers are rather more useful
than messages without.
Really, Gene!
By the time you have a DOM node in Java, there is no line number information.
Surely you are aware of that.
XML is explicitly a line-number-free format. Surely you are aware of that.
You can have the exact same XML document with various different line breaks in
whatever source you used. Surely you are aware of that.
Yes, you can associate line numbers from a particular expression of an XML
document with nodes in your tree, but that is meaningless because it means
nothing with other equivalent expressions. As surely you are aware.
A DOM (Document Object Model) is a tree-structured representation of an XML
document. There are no line numbers in a tree. Surely you are aware of that.
Where line breaks occur between elements has no significance to XML, as I'm so
sure you are aware.
There may be a line number in a particular source file used to represent an
XML, but there really isn't a line number in the XML. To use your lame
analogy, a Java source file might have line numbers, but the resulting class
file doesn't. It might associate a line number from a particular expression of
that source in a debug map, but that isn't going to help you know where the
code is in an equivalent source module with different line breaks.
My point was, really, Gene, that in a DOM the line numbers have no
significance. XML is frequently canonicalized, and "[a]ccording to the W3C, if
two XML documents have the same canonical form, then the two documents are
logically equivalent within the given application context (except for
limitations regarding a few unusual cases)."
<http://en.wikipedia.org/wiki/Canonical_XML>
Since XML is generally used to move information from one module or component
to another, the notion of line numbers between them becomes utterly meaningless.
Really, Gene.
Perhaps if the OP were to explain how they contemplate using line numbers, and
how they plan to assure the numbers have meaning, and why they have to persist
all the way into the DOM where they really have no relevance, things would
become more clear.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg