The W3C Recommendation for XML 1.0 and XML 1.1 contain the following language with regard to attribute value normalization:

"If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character. ... All attributes for which no declaration has been read SHOULD be treated by a non-validating processor as if declared CDATA."

What this means is that the following element should be treated by the parser as having an attribute with a value containing a leading space:

<foo bar=" baz">

However, by default, the MSXML parser treats this element as if it were so declared:

<foo bar="baz">

Obviously, this causes problems when " baz" and "baz" should be treated as different values in XPATH queries and elsewhere. The following code fails to locate our element, assuming our element is declared within a document named document.xml:

MSXML2::IXMLDOMDocumentPtr pDocument;
pDocument.CreateInstance(__uuidof(MSXML2::DOMDocument));
pDocument->load(_T("document.xml"));
// This query will fail:
BSTR bstrQuery = SysAllocString(OLESTR("//foo[@bar=\" baz\"]"));
// While this one would succeed:
// BSTR bstrQuery = SysAllocString(OLESTR("//foo[@bar=\"baz\"]"));
MSXML2::IXMLDOMNodePtr pNode = pDocument->selectSingleNode(bstrQuery); // pNode = NULL
SysFreeString(bstrQuery);

Proper handling of attribute value normalization, among other non-W3C-Recommendation-compliant issues, was addressed beginning with MSXML4. In order to prevent breaking legacy code that relied on the old parser's incorrect behavior, a new parser was introduced. This parser has to be explicitly turned on via the setProperty() function that was added with MSXML4. The following code demonstrates utilizing the new parser to obtain the behavior we expect:

// Use IXMLDOMDocument2Ptr to get the setProperty/getProperty functionality
MSXML2::IXMLDOMDocumentPtr2 pDocument;
// IXMLDOMDocument2Ptr only operates on DOMDocument40 (or later)
pDocument.CreateInstance(__uuidof(MSXML2::DOMDocument40));

// Turn on the new parser in MSXML6; this must be done prior to loading the document
_variant_t varNewParser;
BSTR propName = SysAllocString(OLESTR("NewParser"));
varNewParser.vt = VT_BOOL;
varNewParser.boolVal = VARIANT_TRUE;
pDebugDoc->setProperty(propName, true);
SysFreeString(propName);

pDocument->load(_T("document.xml"));
BSTR bstrQuery = SysAllocString(OLESTR("//foo[@bar=\" baz\"]"));
MSXML2::IXMLDOMNodePtr pNode = pDocument->selectSingleNode(bstrQuery); // pNode != NULL
SysFreeString(bstrQuery);