Instantiate an XML DOM Object (JScript)
This tutorial uses or creates the following files:
File | Description |
---|---|
JScript source code. | |
Output from the application. |
To create the InstantiateDOM JScript project
Create a JScript project. For detailed instructions on how to do this, see Set Up My JScript Project.
Name the project folder InstantiateDOMProj.
Next, we'll add the source code for the InstantiateDOM project.
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!
Copy the code listing above and paste it into your preferred JScript code editor.
Save the file as with InstantiateDOM.js in the current project folder.
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.
When you run the InstantiateDOM project, you should get the following output:
dom: <a>A</a>
The next tutorial shows how to load an XML file into an XML DOM object
Tidak ada komentar:
Posting Komentar