Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
XML
Reporting line number of parse exception?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="rolf, post: 779595"] Hmm, I seem to be missing something basic with regards to SAXParsers. I'm parsing some XML using Java 1.4.2 and SAX, so I extend DefaultHandler and in my startElement() method I detect some kind of error, maybe a missing mandatory attribute. So I throw an exception, and of course I want to report the location (line number and character) within the XML file that the error occurred in. I could throw a SAXParseException that has this information, but... where do I get the location from? It seems likke I could do with a Locator, but DefaultHandler only has a setLocator(), no getLocator(). Surely the parser or the InputSource knows where it's got to in the file when an error occurs - is there no way of getting hold of this information? I'm constructing the parser as follows: SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); InputStream in = new FileInputStream(filename); MyHandler handler = new MyHandler(); InputSource source = new InputSource(in); parser.parse(source, handler); -Rolf [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
XML
Reporting line number of parse exception?
Top