You don't say anything about the technology you are using.
Most of the standard tree models (DOM, JDOM, etc) don't give you any line number information.
It's available from SAX and StAX parsers, but that's a bit low-level.
If you're using Saxon, there's an option to maintain line numbers and retrieve them using the saxon:line-number() extension function.
Incidentally, there are products like DeltaXML that do this for you, and much better that you could hope to achieve in something home-grown.
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference