Source: SaveDOM.js

 

In this demonstration, we first create a DOM object, then fill in the content by calling the loadXML method on the object. Next, we save the object to a file named saved.xml.

JScript Source File (SaveDOM.js)

// Instantiate a DOM object.
var doc = new ActiveXObject("msxml2.DOMDocument.6.0");
doc.async = false;
doc.resolveExternals = false;
doc.validateOnParse = false;

// Load an XML file into the DOM instance.
doc.loadXML
  (
      "<?xml version='1.0'?>\n"
     +"<doc title='test'>\n"
     +"  <page num='1'>\n"
     +"    <para title='Saved at last'>\n"
     +"       This XML data is finally saved.\n"
     +"    </para>\n"
     +"  </page>\n"
     +"  <page num='2'>\n"
     +"    <para>\n"
     +"       This page is intentionally left blank.\n"
     +"    </para>\n"
     +"  </page>\n"
     +"</doc>\n"
  );

// Save the dom to a file.
doc.save("saved.xml");


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

To add SaveDOM.js to the project

  1. Copy the code listing above. Paste it into the JScript code editor, and save the file as SaveDom.js in the current project folder.

Next, run the project. The result should be the output shown in the following topic.