Locators

Although it is very important for an application to know where the parser has got to in a document when an error occurs, as discussed above, it may also wish to know this information at other times.

Locator interface

The parser can tell the application the entity, line number and character number of current event, by instantiating an object that belongs to a class that implements the Locator interface, then giving the application a reference to this object. The Locator interface defines the following methods:

int     getLineNumber();
int     getColumnNumber();
String  getSystemId();
String  getPublicId();

Note that this interface is unchanged in SAX 2.0.

Most of these methods are self-explanatory, given the discussion above, and they are the ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.