[jdom-interest] How can I get the line number of an element?
Rick Horowitz
rickhoro at speakeasy.net
Fri Apr 4 00:00:56 PST 2003
Laurent,
Do you happen to have a code sample that I can follow?
Thanks very much for your help.
Rick
On Tue, 2003-04-01 at 03:48, Laurent Bihanic wrote:
> Hi,
>
> Rick Horowitz wrote:
> > Is there a way to determine the line number of an element and/or
> > attribute when reading an XML file using JDOM? If so, how?
>
> The line number information is available through method getLineNumber() of the
> Locator object provided by the SAXParser. SAXHandler provides the public
> method getDocumentLocator() for getting access to this locator.
> But the SAXHandler instance is well hidden within SAXBuilder. You'll need to
> subclass SAXBuilder to overwrite the createContentHandler() method to store
> the reference to the SAXHandler instance and add a public method to make it or
> the Locator or the actual line number information available.
>
> Be careful though, the information provided by the locator is only valid while
> the parse is ongoing. Thus the only way, in JDOM, to get meaningful line
> numbers is to retrieve this information from a JDOMFactory, when elements are
> being created.
>
> Hope this helps,
>
> Laurent
>
>
More information about the jdom-interest
mailing list