January 21, 2002 - Monitoring XML Loading | 2

The DOMDocument's readyState property can give direct feedback on the XML loading process. 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. We incorporated this event handler in the following box to load an XML file. Type mydvd.xml in the input box and see that the readyState property goes through all four of its values. Type an incorrect name, and see state 3 missing from the list (on some systems). Observe the error message:

We create the DOMDocument object, xmldoc, and then assign checkState() as the onreadystatechange event handler. Then we load the URL entered by the user, url.value. From now on, every change in the readyState property will go through the function checkState() and be recorded. Here is the function checkState():