R
rolf
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
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