readyState Property (DOMDocument)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

readyState Property (DOMDocument)

Indicates the current state of the XML document.

[Script]

Script Syntax

lValue = oXMLDOMDocument.readyState;

Example

The following script 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>
[Visual Basic]

Visual Basic Syntax

lValue = oXMLDOMDocument.readyState

Example

The following Microsoft® Visual Basic® example demonstrates the sequence of ready states when asynchronously loading a document.

Dim WithEvents xmldoc As Msxml2.DOMDocument50
Private Sub Command1_Click()
   Set xmldoc = New Msxml2.DOMDocument50
   xmldoc.Load "books.xml"
   If (xmlDoc.parseError.errorCode <> 0) Then
      Dim myErr
      Set myErr = xmlDoc.parseError
      MsgBox("You have error " & myErr.reason)
   End If
End Sub
Private Sub xmldoc_onreadystatechange()
   Dim state As Integer
   state = xmldoc.readyState
   Text1.Text = Text1.Text & "readyState = " & state & vbCrLf
   If state = 4 Then
      If xmldoc.parseError.errorCode <> 0 Then
         Text1.Text = Text1.Text & xmldoc.parseError.reason & vbCrLf
      Else
         Text1.Text = Text1.Text & "success" & vbCrLf
      End If
   End If
End Sub
[C/C++]

C/C++ Syntax

HRESULT get_readyState(
    long * value);

Parameters

value [out, retval]
The value that indicates the instantiation and download state of the XML document object. It can be one of the following:

LOADING (1) The load is in progress. Reading persisted properties, but not yet parsing data. For readyState definitions, data should be considered equivalent to binary large object (BLOB) properties.
LOADED (2) Reading of the persisted properties completed. Reading and parsing data, but the object model is not yet available.
INTERACTIVE (3) Some data has been read and parsed, and the object model is now available on the partially retrieved data set. Although the object model is available during this state, it is read-only.
COMPLETED (4) The document has been completely loaded, successfully or unsuccessfully.

C/C++ Return Values

S_OK
The value returned if successful.
E_INVALIDARG
The value returned if the value parameter is Null.

Example

See the example in onreadystatechange Event.

Remarks

Long integer. The property is read-only. It returns a value that indicates the instantiation and download state of the XML document object. The value can be one of the following:

State Description
LOADING (1) The load is in progress. Reading persisted properties, but not yet parsing data. For readyState definitions, data should be considered equivalent to binary large object (BLOB) properties.
LOADED (2) Reading of the persisted properties completed. Reading and parsing data, but the object model is not yet available.
INTERACTIVE (3) Some data has been read and parsed, and the object model is now available on the partially retrieved data set. Although the object model is available during this state, it is read-only.
COMPLETED (4) The document has been completely loaded, successfully or unsuccessfully.

This member is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

onreadystatechange Event

Applies to: DOMDocument