A Kick-Start to SAX with C++, Part 3 | CodeGuru

A Kick-Start to SAX with C++, Part 3

This is the third and last article of this series. In the first article, you saw what SAX is, what the Microsoft COM implementation of SAX is, and how to write a simple parser of a XML document. In the second article, you saw how to work around the limitation of having a single handler […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 16, 2006
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This is the third and last article of this series. In the first article, you saw what SAX is, what the Microsoft COM implementation of SAX is, and how to write a simple parser of a XML document. In the second article, you saw how to work around the limitation of having a single handler type registered to the XML reader at a time. In both articles, you ignored anything related to errors. Now, you will see how to implement some simple error handling. Before going any further, I recommend that you read the first and second parts, if you haven’t already.

Microsoft COM Support for Errors Handling

As seen in the previous articles, you can register to the XML reader a content handler, a DTD handler (which will not be covered), and an error handler. In the COM implementation of SAX, ISAXErrorHandler is the interface that provides the error handling functionality.

ISAXErrorHandler has three methods. All of them take the same three parameters:

Parameter Description
ISAXLocator * pLocator Pointer to a locator object that contains information about the file, line, and column where the error occurred
const wchar_t * pwchErrorMessage Textual information about the error
HRESULT hrErrorCode Error code identifying the reason of the error

The three methods of ISAXErrorHandler are:

Method Description
error() Receives notification of a recoverable error
fatalError() Receives notification of non-recoverable errors
ignorableWarning() Receives notifications of warnings

However, in the current implementation all warnings are treated as errors and all errors are non-recoverable. Thus, only fatalError() is called in the current implementation.

ISAXLocator associates a SAX event with a document location. The information stored in the locator is updated for each event. The interface has four methods (table taken from MSDN):

Method Description
getColumnNumber Returns the column number where the current document event ends
getLineNumber Returns the line number where the current document event ends
getPublicId Returns the public identifier for the current document event
getSystemId Returns the system identifier for the current document event
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.