用 ASP 和 Microsoft XML DOM 来创建和保存XML文件

ASP文件:
<%
Dim xmlDoc, rootEl, child1, child2, p
'Create an XML document
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
'Create a root element and append it to the document
Set rootEl = xmlDoc.createElement("root")
xmlDoc.appendChild rootEl
'Create and append child elements
Set child1 = xmlDoc.createElement("child1")
Set child2 = xmlDoc.createElement("child2")
rootEl.appendChild child1
rootEl.appendChild child2
'Add an XML processing instruction
'
and insert it before the root element
Set p=xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore p,xmlDoc.childNodes(
0)
'Save the XML file to the c directory
xmlDoc.Save "c:test.xml"
%>

保存好的XML文件:
<?xml version="1.0"?>
<root>  
  
<child1 />  
  
<child2 />
</root>
posted @ 2008-05-09 09:03  Tuwi  阅读(1127)  评论(0编辑  收藏  举报