I am trying to figre out how to get a line number as to where I threw an exception from the endTag method. I am trying to use the Locator interface, but I keep getting -1 for the line number. Any help would be apreciated.
Thanks
Marc Boorshtein
-
How to get line number in sax? (5 messages)
- Posted by: Marc Boorshtein
- Posted on: January 30 2003 22:32 EST
Threaded Messages (5)
- How to get line number in sax? by Gal Binyamini on January 31 2003 19:47 EST
- How to get line number in sax? by Hari Simhadri on February 03 2003 16:30 EST
- sax tutorial by Dieter Cailliau on February 05 2003 05:00 EST
-
sax tutorial by Gal Binyamini on February 05 2003 08:48 EST
- sax tutorial by Dieter Cailliau on February 05 2003 12:46 EST
-
sax tutorial by Gal Binyamini on February 05 2003 08:48 EST
- sax tutorial by Dieter Cailliau on February 05 2003 05:00 EST
-
How to get line number in sax?[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: January 31 2003 19:47 EST
- in response to Marc Boorshtein
The default SAX parser implementations in some of the JDKs and XML packs had a "performance optimization" of not counting lines, and it allways returned -1 for the line number. The only solution I know of is to switch to another SAX parser implementation (I think the one in JDK1.4 no longer has this "optimization").
Gal -
How to get line number in sax?[ Go to top ]
- Posted by: Hari Simhadri
- Posted on: February 03 2003 16:30 EST
- in response to Marc Boorshtein
I remember trying it a while ago ...
Here is some code
/** Returns a string of the location. */
private String getLocationString(SAXParseException ex) {
StringBuffer str = new StringBuffer();
str.append("Line[");
str.append(ex.getLineNumber());
str.append("] Column[");
str.append(ex.getColumnNumber());
str.append("]");
return str.toString();
} // getLocationString(SAXParseException) -
sax tutorial[ Go to top ]
- Posted by: Dieter Cailliau
- Posted on: February 05 2003 05:00 EST
- in response to Hari Simhadri
this page http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPSAX5.html talks about ContentHandler.setDocumentLocator; a callback invoked once before parsing begins. It knows all about the documents location and the parsing position.
i think the addendum tutorials are excellent: http://java.sun.com/j2ee/1.4/docs/tutorial/index.html -
sax tutorial[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: February 05 2003 08:48 EST
- in response to Dieter Cailliau
Didn't you see Marc allready said he is using a locator? In some SAX implementations, the value returned from the locator for the line number is -1. It doesn't count lines as a performance optimization.
Gal -
sax tutorial[ Go to top ]
- Posted by: Dieter Cailliau
- Posted on: February 05 2003 12:46 EST
- in response to Gal Binyamini
oh. sorry :$