Microsoft KB Archive/221841

From BetaArchive Wiki
Knowledge Base


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));
                

REFERENCES

For additional information about the asynchronous behavior of the Internet Explorer 5.0 XML parser, please see the following article in the Microsoft Knowledge Base:

223337 Loading/saving XML data using the Internet Explorer XML parser



For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:


Additional query words: load IXMLDOMDocument

Keywords: kbprb KB221841