注册本站  论坛  繁體中文

电脑技巧
手机 | MP3 | MP4 | 显卡 | 主板 | 显示器 | 光存储 | 笔记本 | 网络设备 | 移动存储 | 数码相机
键鼠 | CPU | 音箱 | GPS | 电视 | 服务器 | 投影机 | 机箱电源 | 品牌电脑 | 办公打印 |
| 网站首页 | Cisco | Windows | Linux | Java | Dotnet | Oracle | 网页设计 | 平面设计 | 安全 | 软件应用 | 电脑维修 | 办公维修 |
您现在的位置: 电脑技巧 >> Dotnet >> ASP编程 >> Dotnet正文

ASP操作XML的类

文章来源:网页教学网 作者:佚名 更新时间:2008-4-4 17:26:33 【 】 【加入收藏
ASP操作XML的类的说明:
可以完成ASP对XML节点的添加、删除、修改、清空。
进行上述操作,根据条件,操作类型包括:仅对第一个符合条件、及全部符合条件二种。

如:
'将第一条件值替换成新值
'call xml.r_node("/blog/sorts/sort[id='2']/name","分lei2")
'将全部条件值替换成新值
'call xml.r_nodes("/blog/sorts/sort[id='2']/name","分lei2")

dom.save(xmlpath)
set doc=nothing
End Function

function c_node(node)
iserr_=False
set doc=dom.documentElement.selectSingleNode(node)
if not doc is nothing then
doc.text=""
dom.Save(xmlpath)
iserr_=True
end if
set doc=nothing
end function
function c_nodes(node)
dim i
iserr_=False
set doc=dom.selectNodes(node)
if not doc is nothing then
for i=0 to doc.length-1
doc.item(i).text=""
next
dom.Save(xmlpath)
iserr_=True
end if
set doc=nothing
end function


function checknode(nodes,build)
dim doc2,doc3
dim i,f_node_,n_node,newnode
iserr_=True
Set doc = dom.documentElement.selectSingleNode(nodes)
if doc is nothing then
iserr_=False
if build then
nodes=split(nodes,"/")
f_node_=""
n_node=""
for i=0 to ubound(nodes)-1
if nodes(i)="" then
f_node_=f_node_&nodes(i)
f_node_=f_node_&"/"
n_node=f_node_&nodes(i+1)
else
f_node_=n_node
n_node=f_node_&"/"&nodes(i+1)
end if
Set doc2 = dom.documentElement.selectSingleNode(f_node_)
set doc3 = dom.documentElement.selectSingleNode(n_node)
if doc3 is nothing then
Set newnode = dom.createElement(nodes(i+1))
newnode.Text=""
doc2.AppendChild(newnode)
Set newnode=nothing
end if
set doc2=nothing
set doc3=nothing
next
dom.Save(xmlpath)
end if
end if
set doc=nothing
End Function

function joinxml(inset_node,xmlstr)
dim oldxml,newxml,rootNewNode
iserr_=False
Set oldXML = Server.CreateObject("Microsoft.XMLDOM")
oldXML.load(xmlpath)
set doc=oldxml.documentElement.selectSingleNode(inset_node)
if not doc is nothing then
iserr_=True
Set newXML = Server.CreateObject("Microsoft.XMLDOM")
newXML.loadXML(xmlstr&vbcrlf)
set rootNewNode=newXML.documentElement
doc.appendChild(rootNewNode)
oldxml.Save(xmlpath)
end if
set oldXML=nothing
set newXML=nothing
End Function

function r_node(node,newstr)
iserr_=False
set doc=dom.documentElement.selectSingleNode(node)
if not doc is nothing then
doc.text=newstr
iserr_=True
end if
set doc=nothing
dom.Save(xmlpath)
End Function
function r_nodes(node,newstr)
dim i
iserr_=False
set doc=dom.selectNodes(node)
if not doc is nothing then
for i=0 to doc.length-1
doc.item(i).text=newstr
next
iserr_=True
end if
set doc=nothing
dom.Save(xmlpath)
End Function
function replace_node(node,newstr)
call add_node(node,newstr,0)
End Function
function add_node(node,newstr,num)
set doc=dom.selectNodes(node)
if not doc is nothing then
if doc.length >=num then
call d_node(node)
end if
end if
set doc=nothing
call joinxml(left(node,instrrev(node,"/")-1),newstr)
End Function

function f_node(node)
dim getnode
set doc=dom.documentElement.selectSingleNode(node)
if not doc is nothing then
iserr_=True
getnode=doc.Text
else
getnode=""
iserr_=False
end if
set doc=nothing
f_node=getnode
end function

function count(node)
dim nodenum
nodenum=array(0,0,"")
iserr_=False
set doc=dom.selectNodes(node)
if not doc is nothing then
nodenum(0)=doc.length
nodenum(2)=doc.item(0).xml
if doc.item(0).hasChildNodes() then
nodenum(1)=doc.item(0).childNodes.length
end if
iserr_=True
end if
count=nodenum
end function

function id_(str)
id_=String(10-len(str),"0")
end function
function now_(dd)
dim m,d,h,mm
if not isdate(dd) then d=now()
dd=cdate(dd)
m=month(dd)
d=day(dd)
h=hour(dd)
mm=Minute(dd)
if m<10 then m="0"&m
if d<10 then d="0"&d
if h<10 then h="0"&h
if mm<10 then mm="0"&mm
now_=year(dd)&"-"&m&"-"&d&" "&h&":"&mm&":"&Second(dd)
end function
end class
%>
  • 上一篇Dotnet:

  • 下一篇Dotnet:
  • 最 新 热 门
     ASP错误解决:800a003a错误
     ASP实例:幻灯片新闻代码
     ASP操作XML的类
     asp控制xml数据库的6段代码
     ASP操作XML文件的主要方法和实现
     spring 中加载xml配置文件的方式
     XML文件上传技术
     DataSet(DataTable)与XML互转
     对XML文档进行添、删、改、查的程序
     XSL的控制语句
    最 新 推 荐
     ASP错误解决:800a003a错误
     ASP实例:幻灯片新闻代码
     ASP操作XML的类
     asp控制xml数据库的6段代码
     ASP操作XML文件的主要方法和实现
     ASP关于类的Let,Set和Get的用法的异同
     ASP对XML文档中文本的增加、删除、修改、查…
     ASP实例:读取xml文件的程序
     ASP实例:是否支持XmlHttp组件的判断
     XMLHTTP实时进行表单数据的校验
    相 关 文 章

    ASP错误解决:800a003a错误
    ASP实例:幻灯片新闻代码
    asp控制xml数据库的6段代码
    ASP操作XML文件的主要方法和实现
    spring 中加载xml配置文件的方式
    DataSet(DataTable)与XML互转
    用WatiN对ASP.NET页面进行单元测试
    ASP.NET中DataTable对象
    ASP.NET中的DataColumn对象
    ASP.Net全局变量的设置和读取方法

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告

     

    Copyright 2006-2008 pcjx.com All Rights Reserved
    电脑技巧 版权所有 粤ICP备06059145号 地图
    本网站所有内容未经许可不得转载或做其他使用