asp写入xml

使用ASP添加xml节点功能
相关方法:
createNode(type, name, nameSpaceURI);//建立一个指定型态、名称,及命名空间的新节点
setAttribute( name , value );//在指定的节点插入一个新的属性,如果属性名已经存在,则替换原属性名的值
appendChild(newChild);//加上一个节点当作指定节点最后的子节点。
insertBefore(newChild,refChild);//在指定的节点前插入一个子节点。
xmlDocument.save(url);//保存操作.
实例:
Vbscript
 
引用:

set Doc = CreateObject("Microsoft.XMLDOM")
Doc.async = false
Doc.load(Server.MapPath("data.xml"))
set root = Doc.DocumentElement
set book = Doc.createNode(1,"book","")
set bookname = Doc.createNode(1,"name","")
set publisher = Doc.createNode(1,"publisher","")
set img = Doc.createNode(1,"img","")
bookname.text = "Coldfusion"
publisher.text = "上海教育出版社"
img.text = "img/5.jpg"
book.appendChild(bookname)
book.appendChild(publisher)
book.appendChild(img)
root.appendChild(book)
Doc.Save(Server.MapPath("data.xml"))
call Doc.getElementsByTagName("book").item(Doc.DocumentElement.childNodes.length-1).setAttribute("cost","200") '通过length来获取需要添加属性的节点所在的位置.
Doc.Save(Server.MapPath("data.xml"))

 


Xml
 
引用:

<data>
<book cost="56">
<name>Dreamweaver</name>
<publisher>上海科技出版社</publisher>
<img>img/dw.jpg</img>
</book>
<book cost="62">
<name>Flash</name>
<publisher>铁道出版社</publisher>
<img>img/flash.jpg</img>
</book>
<book cost="48">
<name>Firweorks</name>
<publisher>教育出版社</publisher>
<img>img/fw.jpg</img>
</book>
</data>

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值