SAX的异常处理。

SAXParseException 
SAXException
SAXParseException 主要用来处理,解析XML过程中出现的不可恢复的异常。比如一个xml中的某个元素不完整。SAXException
可能在startDocument(),endDocument(),startElement(),endElement(),characters()中抛出。

Handling NonFatal Errors

A nonfatal error occurs when an XML document fails a validity constraint. If the parser finds that the document is not valid, then an error event is generated. Such errors are generated by a validating parser, given a DTD or schema, when a document has an invalid tag, when a tag is found where it is not allowed, or (in the case of a schema) when the element contains invalid data.
 
值得注意的是它处理的a recoverable parser error.和前面的异常处理的机制是不同的。默认的DefaultHandler对这种错误是不做任何处理的,如果要额外处理,只要复写这个函数即可。
 public void error (SAXParseException e) throws SAXException

Handling Warnings

Warnings, too, are ignored by default. Warnings are informative can only be generated in the presence of a DTD or schema. For example, if an element is defined twice in a DTD, a warning is generated. It's not illegal, and it doesn't cause problems, but it's something you might like to know about because it might not have been intentional.

你可能感兴趣的:(xml)