Compability: Internet Explorer
This method saves an XML document to a specified location.
There are four types of objects that can be specified as the parameter to this method, and each behaves slightly differently.
XML:
<Albums>
<Album ref="CD720">
<category>Pop</category>
<title>Come On Over</title>
<artist>Shania Twain</artist>
</Album>
<Album ref="CD024">
<category>Country & Western</category>
<title>Red Dirt Girl</title>
<artist>Emmylou Harris</artist>
</Album>
</Albums>
VBScript:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("albums.xml")
Set NewText = objXMLDoc.createTextNode("Country")
Set Category = objXMLDoc.documentElement.lastChild.firstChild
Set OldText = Category.firstChild
Category.replaceChild NewText, OldText
objXMLDoc.save("C:\Temp\newAlbums.xml")
In this example we pass a string parameter. The 'albums.xml' file is loaded and the text of the last album's 'category' element is altered to 'Country'. This modified XML file is then saved in the Temp directory under the name of 'newAlbums.xml'.
XML:
<staff>
<employee ssn="123456" pay="3">
<name>John Sullivan</name>
<position>&snrex;</position>
</employee>
<employee ssn="987654" pay="2">
<name>Mary Lopez</name>
<position>&pa;</position>
</employee>
</staff>
JavaScript:
xml_doc1 = new ActiveXObject("Microsoft.XMLDOM");
xml_doc2 = new ActiveXObject("Microsoft.XMLDOM");
xml_doc1.async = false;
xml_doc1.load("staff.xml");
xml_doc1.save(xml_doc2);
root = xml_doc2.documentElement;
document.write(root.xml);
John Sullivan &snrex; Mary Lopez
&pa;
In this next example, we load the 'staff.xml' file and create a copy of it. To test that the operation has been successful, the code displays the XML of the copy.