Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CHAPTER 7 <strong>XML</strong> Parsers and Transformations<br />
The Error Handler is the component of a SAX parser that responds to errors<br />
discovered by the SAX parser when it’s reading the <strong>XML</strong> document. There are<br />
three types of errors: warnings, error, and fatal error.<br />
A warning indicates that the SAX parser encountered something unusual in the<br />
<strong>XML</strong> document, but it wasn’t enough to stop it from transforming the <strong>XML</strong><br />
document. An error is more serious than a warning. It doesn’t prevent the parser<br />
from continuing; however, the transformed document might be properly transformed.<br />
A fatal error prevents the SAX parser from continuing.<br />
Each error has a corresponding error handler that’s called when the SAX parser<br />
encounters it. A handler is a method with instructions on how to respond to the<br />
error. These methods are warning(), error(), and fatalError().<br />
You don’t need to be concerned with how error handlers work. However, you do<br />
need to understand how to react to the error messages that these error handlers<br />
display. Each SAX parser has its own set of error messages, so you’ll need to refer<br />
to the documentation that comes with your SAX parser to know how to respond to<br />
error messages.<br />
The DTD Handler<br />
The DTD Handler reads the Data Type Definition (DTD) (see Chapter 3) and then<br />
uses the DTD to validate tags in the <strong>XML</strong> document. If an <strong>XML</strong> tag violates the<br />
DTD, the DTD Handler causes the Error Handler to display a warning or error<br />
message on the screen indicating the nature of the problem. We illustrate this in the<br />
following <strong>XML</strong> document and DTD.<br />
The <strong>XML</strong> document:<br />
<br />
<br />
99