3 different ways to generate files _ Application Tips
Source: Internet
Author: User
<% @language = "JScript"%>
<%
Using the FSO Build
var fso=server.createobject ("Scripting.FileSystemObject")
Fso. CreateTextFile (Server.MapPath ("./") + "/test1.xml"); Create a file.
f = fso. GetFile (Server.MapPath ("./") + "/test1.xml");
ts = F.openastextstream (2,-2);
Ts. Write ("<root><name>" +escape ("China"). Replace (/%u (\w{4})/g,function ($0,$1) {return "&#" + ("0x" +$1)-0 ). ToString (10) + ";"}) + "</name></root>");
Ts. Close ();
%>
<%
Using Adodb.strea generation
var objstream = Server.CreateObject ("ADODB.") Stream ")
With (objstream)
{
type=2;
mode=3;
Open ();
Charset= "Utf-8";
Position = Objstream.size
writetext= "<root><name>" +escape ("China"). Replace (/%u (\w{4})/g,function ($0,$1) {return "&#" + ("0x" +$ 1) -0). ToString (10) + ";"}) + "</name></root>";
SaveToFile (Server.MapPath ("Test2.xml"), 2)
Close ()
}
var objstream = null;
%>
<%
<--
Using Microsoft.dom generation
var doc = new ActiveXObject ("Msxml2.domdocument"); Ie5.5+,createobject ("Microsoft.XMLDOM")
Loading documents
Doc.load ("Test3.xml");
To create a file header
var p = doc.createprocessinginstruction ("xml", "version= ' 1.0 ' encoding= ' utf-8 '");
Add File Headers
Doc.appendchild (P);
To get the root contact when loading directly
var root = doc.documentelement;
Create root contacts in two ways
var root =
Doc.createelement ("root");
var root = Doc.createnode (1, "Root", "");
Creating Child contacts
var n = doc.createnode (1, "name", "");
Specify Child Contact text
N.appendchild (Doc.createtextnode Escape ("China"). Replace (/%u (\w{4})/g,function ($0,$1) {return "&#" + ("0x" +$1)-0 ). ToString (10) + ";"}));
Add Child contacts
Root.appendchild (n);
Copy Contacts
Create a data segment
var c = doc.createcdatasection ("This is a CDATA");
C.text = "Hi,cdata";
Adding data segments
Root.appendchild (c);
Add Root Contact
Doc.appendchild (root);
XML save (required on server, client with FSO)
Doc.save (Server.MapPath ("./") + "/test3.xml");
-->
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service