|
|
||||
首页
文学作品 网页设计 平面设计 程序设计 考试认证 基础办公 QQ资源 服务器架设 网站运营 网页资源
|
|
|
| 汉南在线 → 网页设计 → Asp动态程序 | |||||||||||
<% class cls_xml private sfilename private sxmlfile private sobjxml property let filename(value) sfilename=value end property property get filename filename=sfilename end property property get objxml set objxml=sobjxml end property private sub class_initialize() sfilename="" sxmlfile="" sobjxml=null end sub private sub class_terminate() sobjxml.close set sobjxml=nothing end sub private sub createfile()'创建xml文件 Set oPI=sobjXML.createProcessingInstruction("xml", "version=""1.0"" encoding=""GB2312""") sobjXML.insertBefore oPI,sobjXML.childNodes(0) savefile end sub public function loadfile()'读取xml文件 sxmlfile=server.MapPath(sfilename) set sobjxml=server.CreateObject("msxml2.domdocument") sobjxml.load(sxmlfile) sobjxml.async=false if sobjxml.parseError.ErrorCode = 0 then loadfile=true else createfile end if end function public sub addnode(byval parentnode,byval childnode,byval nodetext)'添加节点 if parentnode="" then sobjxml.appendchild (sobjxml.createElement(childnode)) else set child=sobjxml.createElement(childnode) child.text=nodetext sobjxml.selectsinglenode(parentnode).appendchild child end if savefile end sub public sub addattr(byval parentnode,byval attrtype,byval attrname,byval attrtext)'添加属性 set sattribute=sobjxml.createNode(attrtype,attrname,"") sattribute.text=attrtext if parentnode="" then sobjxml.documentElement.setattributenode sattribute else sobjxml.documentElement.selectsinglenode(parentnode).setattributenode sattribute end if savefile end sub private function getnode(byval nodepath,byval attrname,byval attrvalue)'获得节点对象 if attrname="" then set getnode=sobjxml.documentElement.selectsinglenode(nodepath) else set getnode=sobjxml.documentElement.selectsinglenode("//"&nodepath&"[@"&attrname&"='"&attrvalue&"']") end if end function public function getnodename(byval nodepath,byval attrname,byval attrvalue)'获得节点名称 getnodename=getnode(nodepath,attrname,attrvalue).nodename end function public function getnodevalue(byval nodepath,byval attrname,byval attrvalue)'获得节点内容 getnodevalue=getnode(nodepath,attrname,attrvalue).text end function public sub modifynodevalue(byval nodepath,byval newtext,byval attrname,byval attrvalue)'修改节点内容 set newnode=getnode(nodepath,attrname,attrvalue) newnode.text=newtext savefile end sub public function getnodeattrname(byval nodepath,byval attrname,byval attrname_,byval attrvalue_)'获得节点属性名称 getnodeattrname=getnode(nodepath,attrname_,attrvalue_).getattributenode(attrname).nodename end function public function getnodeattrvalue(byval nodepath,byval attrname,byval attrname_,byval attrvalue_)'获得节点属性值 getnodeattrvalue=getnode(nodepath,attrname_,attrvalue_).getattributenode(attrname).nodevalue end function public sub modifynodeattrvalue(byval nodepath,byval attrname,byval newtext,byval attrname_,byval attrvalue_)'修改节点属性值 set newattr=getnode(nodepath,attrname_,attrvalue_).getattributenode(attrname) newattr.text=newtext savefile end sub public sub delnode(byval parentnodepath,byval parentnodeattrname,byval parentnodeattrvalue,byval childnodepath,byval childnodeattrname,byval childnodeattrvalue)'删除节点 if parentnodepath="" then set parentnode=sobjxml.documentElement else set parentnode=getnode(parentnodepath,parentnodeattrname,parentnodeattrvalue) end if set childnode=getnode(childnodepath,childnodeattrname,childnodeattrvalue) parentnode.removechild childnode savefile end sub public function getchildlength(byval nodename,byval attrname,byval attrvalue)'获得节点长度 if nodename="" then getchildlength=sobjxml.documentElement.childnodes.length else getchildlength=getnode(nodename,attrname,attrvalue).childnodes.length end if end function private sub savefile()'保存文件 sobjxml.save(sxmlfile) end sub end class %>
| |||||||||||
| >> 相关文章 | |||||||||||
|
授权使用:汉南在线 http://www.hzwz.net/(2008-2009) Copyright (c) 2002-2007 汉南在线. All Rights Reserved . 经营许可证:陕ICP备05000109号 Powered by:汉南在线 |