Gathering Document Information

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Gathering Document Information

These properties can be used to get the following information about the document parsing process.

  • doctype

    The document type definition (DTD) accompanying the document.

  • implementation

    The implementation for the document.

  • parseError

    The last error to occur while parsing.

  • readyState

    Information about the state of the XML document.

  • url

    The URL, if any, of the XML file being loaded and parsed.

For more information about error reporting, see IXMLDOMParseError.

The readyState property is critical for programs that use Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office asynchronously to improve performance. When loading XML documents asynchronously, your programs may need to check the state of the parsing process. MSXML provides four states, numbered one through four: loading, loaded, interactive (parsing), and completed. The following Microsoft JScript® and HTML example demonstrates the sequence of ready states when asynchronously loading a document.

<script>
var xmldoc;
function Load()
{
    xmldoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
    xmldoc.onreadystatechange = CheckState;
    xmldoc.load(URL.value);
   if (xmlDoc.parseError.errorCode <> 0) {
      var myErr = xmlDoc.parseError;
      alert("You have error " + myErr.reason);
   }
}
function CheckState()
{
    var state = xmldoc.readyState;
    RESULTS.innerHTML += "readyState = " + state + "<BR>"
    if (state == 4)
    {
      var err = xmldoc.parseError;
        if (err.errorCode != 0)
          RESULTS.innerHTML += err.reason + "<BR>"
        else
          RESULTS.innerHTML +="success" + "<BR>"
    }
}
</script>
URL: <input type=text size=60 id=URL>
<input type=button value=LOAD onclick="jscript:Load()">
<div id=RESULTS style="color:red; font-weight:bold;"></div>