<?xml version="1.0" encoding="gb2312"?>
<books>
<book>
<name>ASP程序设计</name>
<author>尚俊杰</author>
<price>¥20</price>
</book>
<book>
<name>JSP程序设计</name>
<author>jsper</author>
<price>¥40</price>
</book>
</books>
Loadxml.asp
<%
Set xmldom=server.CreateObject("microsoft.xmldom")
xmldom.load(server.mappath("book.xml"))
xmldom.loadxml "<?xml version=""1.0"" encoding=""gb2312""?><books></books>"
Set root=xmldom.documentelement
Set book=xmldom.createelement("book")
root.appendchild(book)
Set name")
name.text="PHP程序设计"
book.appendchild(name)
Set author=xmldom.createelement("author")
author.text="PHPer"
book.appendchild(author)
Set price=xmldom.createelement("price")
price.text="¥50"
book.appendchild(price)
xmldom.save(server.mappath("loadxml.xml"))
%>
Load.asp
<%
Set xmldom=server.CreateObject("microsoft.xmldom")
xmldom.load(server.mappath("book.xml"))
Set root=xmldom.documentElement
Set book=root.appendchild(xmldom.createElement("book"))
Set name")
name.text="JSP程序设计"
book.appendchild(name)
Set author=xmldom.createElement("author")
author.text="JSPer"
book.appendchild(author)
Set price=xmldom.createElement("price")
price.text="¥50"
book.appendchild(price)
xmldom.save(server.mappath("load.xml"))
%>
Insertbefore.asp
<%
Set xmldom=server.CreateObject("microsoft.xmldom")
xmldom.load(server.mappath("book.xml"))
Set root=xmldom.documentElement
Set book=xmldom.createElement("book")
root.insertbefore book,root.childnodes(1)
Set name")
name.text="jsp程序"
book.appendchild(name)
Set author=xmldom.createElement("author")
author.text="jsper"
book.appendchild(author)
Set price=xmldom.createElement("price")
price.text="¥50"
book.appendchild(price)
xmldom.save(server.mappath("insertbefore.xml"))
%>
Createtag.asp
<%
set tempxml=server.createobject("microsoft.xmldom")
tempxml.load server.mappath("book.xml")
set xmlnode=tempxml.documentelement.childNodes(1)
set element=tempxml.createelement("introduction")
element.text="Good Book"
xmlnode.appendchild element
tempxml.save server.mappath("ex2.xml")
%>
Createattr.asp
<%
set tempxml=server.createobject("microsoft.xmldom")
tempxml.load server.mappath("book.xml")
'set xmlnode=tempxml.getElementsByTagName("books").item(0).childnodes(0)
Set xmlnode=tempxml.documentelement.firstchild
set element=tempxml.createattribute("introduction")
element.text="good book!"
xmlnode.attributes.setnameditem element
tempxml.save server.mappath("attr.xml")
%>