Creating an XML file in the client You can use the FileSystemObject (FSO) object or use XML Document Object Model (DOM). If you use FSO, the client must install Window Script 5.5, using XML DOM, you need to install Microsoft® XML Core Services on the client. Security needs to enable ActiveX controls in the IE security settings.
1. Create an XML file using FSO
Use the GetSpecialFolder method for the FSO object to get the directory where you want to create files (settings for the GetSpecialFolder method), see the Window script technology document), then create a text file using the CreateTextFile method and get a reference to this file, calling text file objects. The WriteLine method writes content in the file and finally closes the object.
It is worth noting that when using CreateTextFile creation file, the last indicator file creation method should be set to True to represent in Unicode mode, and set the XML file encoding to UTF-16, which creates the XML file to be used normally .
Function CreateXML () {
Var Fso, TempFolder, Xmlfile, Schar;
Fso = New ActiveXObject ("scripting.filesystemObject");
TempFolder = fso.getspecialfolder (0);
XMLFile = fso.createtextFile (TempFolder "XML.xml", true, true);
SCHAR = '/ r';
XMLFile.WriteLine (' XML Version = "1.0" encoding = "UTF-16"?>' schar);
XMLFile.writeline ('
FOR (var i = 0; i <10; i ) {
XMLFile.Writeline ('
}
XMLFile.writeLine (' document>');
XMLFile.Close ();
}
script>
2. Create an XML file using XML DOM
First create a DomDocument object, call its LOAD method to load a local file, if the file does not exist during the loading process, then construct the document content string, then call the loadXML method to load XML content, and finally call Save Method write a file.
Creating an XML file using XML DOM requires a very careful content format correct, otherwise there will be no content in the created file, because XMLDOC has been judged when writing files, if not correct, the Save method will fail.
Function CreateXML () {
VAR XMLDoc, XMLNode;
Xmldoc = New ActiveXObject ("msxml2.domdocument.4.0");
XMLDoc.Load ("c: //xml.xml"); schar = '/ r';
XmlHead = ' XML Version = "1.0" encoding = "UTF-16"?>' scha;
XMLTITE = '
XMLNode = '';
FOR (var i = 0; i <10; i ) {
XMLNode = XMLNode '
}
XMLFOOT = ' document>';
Strxml = Xmlhead XMLTITLE XMLNode XMLFOOT;
XMLDoc.LoadXML (STRXML);
XMLDoc.save ("c: //xml.xml");
}
script>