XML Parsing: Fatal vs Non-Fatal Errors Explained

This article explores the distinction between fatal and non-fatal errors within the World Wide Web Consortium (W3C) XML parsing specification. It outlines the core definitions, parser behavior requirements, and common examples of both error types, illustrating why XML parsers handle structural malformations drastically differently from validation issues.

The W3C XML Error Classifications

The W3C XML specification defines strict rules for how conforming XML processors must handle errors. These errors are fundamentally divided into two major categories:

  1. Fatal Errors: Violations of XML well-formedness constraints or internal processor limits.
  2. Non-Fatal Errors (Errors and Validity Errors): Violations of validity constraints (defined by DTDs or XML Schemas) or violations of optional specification rules.

Fatal Errors in XML

A fatal error occurs when an XML document violates the fundamental syntax rules required to be considered “well-formed” XML.

Required Parser Behavior

When an XML parser encounters a fatal error, the W3C specification mandates strict and non-negotiable behavior, often referred to as draconian error handling: * The processor must immediately stop normal processing. * The processor must not continue passing parsed data to the downstream application. * The processor must report the error to the host application.

The goal of this design is to prevent software from guessing the author’s intent or parsing malformed documents, which historically caused widespread interoperability issues in HTML.

Common Examples of Fatal Errors


Non-Fatal Errors (Validity Errors and Warnings)

A non-fatal error occurs when an XML document is syntactically well-formed but violates specific validity constraints defined by an associated document type definition (DTD) or XML Schema (XSD), or when a recoverable violation of the specification occurs.

Required Parser Behavior

Unlike fatal errors, non-fatal errors do not require the parser to halt execution: * The processor must detect and report the error to the calling application. * The processor may continue normal parsing and passing data to the application. * Non-validating parsers may ignore validity constraints altogether without reporting errors.

Common Examples of Non-Fatal Errors


Key Takeaway

The fundamental difference lies in well-formedness versus validity:

Attribute Fatal Error Non-Fatal Error
Root Cause Violation of core XML grammar (Well-formedness) Violation of a specific schema/DTD (Validity)
Parser Requirement Halt normal execution immediately Report issue and optionally continue
Application Impact Data stream is cut off; document rejected Document is parsed; application handles validation flag