asp控制xml数据库的代码介绍
发布时间:2023-09-04 10:14:08 所属栏目:Asp教程 来源:
导读:建立一个XML数据库data.xml
<?xml version="1.0"?><records><record><name>caca</name><qq>154222225</qq><email>root@3ney.com</email></record><records>
建立对象CreateObject
set xmldoc=ser
<?xml version="1.0"?><records><record><name>caca</name><qq>154222225</qq><email>root@3ney.com</email></record><records>
建立对象CreateObject
set xmldoc=ser
建立一个XML数据库data.xml <?xml version="1.0"?><records><record><name>caca</name><qq>154222225</qq><email>root@3ney.com</email></record><records> 建立对象CreateObject set xmldoc=server.createobjcet("microsoft.xmldom")xmldoc.load(server.mappath("data.xml") 选定节点SelectNode 这些Node可以很简单的定位: xmldoc.childnodes(0)xmldoc.childnodes(1)xmldoc.childnodes(1).childnodes(0)xmldoc.childnodes(1).childnodes(0).childnodes(0)xmldoc.childnodes(1).childnodes(0).childnodes(0).textxmldoc.childnodes(1).childnodes(0).childnodes(1)xmldoc.childnodes(1).childnodes(0).childnodes(1).textxmldoc.childnodes(1).childnodes(0).childnodes(2)xmldoc.childnodes(1).childnodes(0).childnodes(2).text 是不是定位很简单呀,还有个方法,比如定位<name> xmldoc.selectsinglenode("//name") 给节点赋值(修改节点的值) 学会了定位节点,利用其属性,就可以修改或者赋值了 例如,把<name>的值caca改为wawa xmldoc.selectsinglenode("//name").text="wawa"xmldoc.save(server.mappath("data.xml")) 创建新的节点CreatenewNode 用createelement或者createnode("","","") 例如:在record下新建个<age>,只需要一句就搞定: xmldoc.selectsinglenode("//record").appendchild(xmldoc.createelement("<age>")) 给<age>赋值 xmldoc.selectsinglenode("//age").text="20"xmldoc.save(server.mappath("data.xml")) 删除一个节点DeleteNode 你必须明确你想删除的这个节点的父节点,以及这个节点的特征 例如:删除<qq>节点 xmldoc.selectsinglenode("//record").removechild(xmldoc.selectsinglenode("//qq")) (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐