PRB: MSXML 4.0 SAX Parser Raises Error Event Before startElement Event (315504)
The information in this article applies to:
This article was previously published under Q315504 SYMPTOMS
When you use the MSXML 4.0 Simple API for XML (SAX) parser to validate an element that contains an attribute that is not valid (for example, if the attribute is not defined in the schema, or the attribute contains a value that is not valid), the SAX parser raises the error event of ISAXErrorHandler (IVBSAXErrorHandler) before the parser raises the startElement event of ISAXContentHandler (IVBSAXContentHandler). When the SAX parser raises the error event, only the line number and column number information that is associated with ISAXLocator is available to identify the faulty attribute, instead of the element name that contains the attribute.
CAUSE
Before the MSXML SAX parser fires the startElement event, the parser parses and validates the attributes on the element, builds the ISAXAttributes attribute collection, and then passes the ISAXAttributes attribute collection as an input parameter to the SAX ContentHandler interface ( ISAXContentHandler::startElement), as follows:
HRESULT STDMETHODCALLTYPE ISAXContentHandler::startElement(
/* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ wchar_t __RPC_FAR *pwchRawName,
/* [in] */ int cchRawName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes)
If a validation error occurs on the attribute, the SAX parser raises the error event before the parser fires the startElement event.
RESOLUTION
To work around this problem, identify the name of the XML element that contains an attribute or attribute value that is not valid when you use the SAX validation feature in MSXML 4.0. To do this, either use the line number and column number information that the parser returns to identify the faulty attribute, or use the following method:
- Trap and store the SAX validation error code that the SAX parser generates when the parser finds an attribute or attribute value that is not valid in a global variable in the IVBSAXErrorHandler_error procedure.NOTE: In the October 2001 RTM release of MSXML 4.0, this error code is -2147467259.
- Check the global variable for the error code in the IVBSAXContentHandler_startElement event procedure that the SAX parser fires afterward to determine whether the element that the parser parses contains an attribute or attribute value that is not valid.
- Use the strQName or strLocalName parameters that the parser passes to the IVBSAXContentHandler_startElement event to determine the name of the XML element when the conditional check for the error code for the attribute or attribute value that is not valid evaluates to TRUE.
- Clear the global variable each time the check for the error code for the attribute or attribute value that is not valid evaluates to TRUE.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 4/12/2002 |
---|
Keywords: | kbprb KB315504 |
---|
|