Microsoft KB Archive/221841

= PRB: No Access XML Object Model After Call to XML Parser Load Method =

Article ID: 221841

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q221841



SYMPTOMS
The load method returns successfully but errors occur when accessing the MSXML Document Object Model. The XML document is valid, well-formed, and it contains no errors.

This behavior may be intermittent and does not occur when loading the XML document from the local file system (file://).



CAUSE
By default, the XML parser loads and parses an XML file asynchronously over HTTP. This means that portions of the document's object model will not be available to code immediately after load returns.



RESOLUTION
To ensure the document is loaded, either:
 * Set the async property to false before calling the load method. OR


 * Write the onreadystatechange event procedure of the DOMDocument object, and check to see if the readystate property is "Complete" prior to accessing the DOM objects (value of 4).



MORE INFORMATION
Here is an example fragment of VBScript that uses the async property: Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.async = false xmlDoc.load strURLofXMLDoc Here is the equivalent solution in a Visual C++ host: MSXML::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML::DOMDocument)); pDOMDoc->put_async(VARIANT_FALSE); VARIANT_BOOL varResult = DOMDoc->load(_variant_t(bstrURLofXMLDoc));

