Source: InstantiateDOM.js

 

In this application, we create an XML DOM object and load an XML string into it.

JScript Source File (InstantiateDOM.js)

// Instantiate a DOM object at run time.
var dom = new ActiveXObject("msxml2.DOMDocument.6.0");
dom.async = false;
dom.resolveExternals = false;
dom.loadXML("<a>A</a>");

// Display the content of the object.
alert("dom: "+dom.xml);

// Helper function
function alert(str)
{
   WScript.Echo(str);
}

Try It!

  1. Copy the code listing above and paste it into your preferred JScript code editor.

  2. Save the file as with InstantiateDOM.js in the current project folder.

  3. Run the JScript file.

    You can run the script using the "cscript InstantiateDOM.js" command in aComand Promnpt window for console script execution or by double-clicking on InstantiateDOM.js in Windows Explorer to run it as a Windows script using wscript.exe.

    The result should be the output shown in the following topic.