January 20, 2002 - The Multiple States of XML Loading | 2 | WebReference

January 20, 2002 - The Multiple States of XML Loading | 2

Yehuda Shiran January 20, 2002
The Multiple States of XML Loading
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

The DOMDocument object has a very extensive set of properties, methods, and events to deal with reading XML files and loading their data in. The readyState property can give direct feedback on the reading processes. Here are the possible values for readyState:

StateShort DescriptionLong Description
1LoadingPreparing to read the XML file. Did not try yet.
2LoadedReading and parsing the XML file. Object model still not available.
3InteractivePart of the XML file successfully parsed and read in. Object model partially available for read only.
4CompletedLoading of the XML file has been completed, successfully or unsuccessfully.

When you read an XML file successfully, the readyState property goes through all four states: 1,2,3, and 4. When you are unsuccessful in reading an XML file, the readyState property may skip 3 on some operating systems. Obviously, it is very difficult to know exactly when the readyState property changes its value. For this very purpose the DOMDocument object provides the onreadystatechange event handler.