Hi,
I'm using apache DefaultHandler SAX to interpret xml file.
supposed the xml file as:
<a>....</a>
<a>...</a>
<a>...</a>
...
<a>...</a>
and the dtd as
<!ELEMENT a EMPTY>
namely not allowing PCDATA:
</a>no letter here<a></a>
there are some methods in this handler, such as
public void startElement()
public void endElement( String namespaceURI,
String localName, String qName ) throws SAXException
public void error(SAXParseException e) throws SAXException {
}
..
for every <a></a>, all above methods involved to process them. but the
hanlders reports the error
org.xml.sax.SAXParseException: The content of element type "a" must
match....
at the end of processing xml file.
I'm wondering,
1. why it reports the error that late?
2. how to stop processing xml file whenever error found?
--
Thanks lots
John
Toronto
Oliver Wong - 25 Jan 2006 19:19 GMT
> Hi,
>
[quoted text clipped - 36 lines]
>
> 1. why it reports the error that late?
Probably your SAX parser is first checking that the XML is well formed,
and then only afterwards checking if it is valid. This is generally
reasonable behaviour, because there's no point in checking for validity if
the XML is not even wellformed. An example of a not well formed XML
document:
<xml>
<<><><><><<><><>>><><
</xml>
> 2. how to stop processing xml file whenever error found?
Code the intelligence for error detection in your SAX event handling
methods.
- Oliver