• --:)欢迎访问锋网源码(:--
  • 首页
  • RSS订阅
  • 常用软件
  • 网页模板
  • 网站运作
  • 锋网学院
  • 智能建站
  • 时代互联
  • 中国红网
  • 中资源!
  • 繁體中文

  • 学院首页
  • 新闻资讯
  • 网站运营
  • 网站开发
  • 美工设计
  • 数据库类
  • 服务器类
  • 网络应用
  • 操作系统
  • 软件教学
编程开发   认证考试   网络安全   文章搜索: 高级搜索
会员登录/控制面版 您的位置: 学院首页 >> 网站开发 >> ASP教程 >> 文章内容
 

精彩推荐

 
 

本类推荐文章

  • ASP教程 插入Access记录后..
 
 

本类阅读排行

  • IIS的安装和配置全过程
  • ASP教程:制作登陆验证页面程..
  • www 56.com.cn 电影-www 56...
  • ASP教程 插入Access记录后..
  • “x365x”“纯爱社区”关键词..
  • 用ASP实现一个真正的注册页面..
  • 用ASP将数据读数导出EXCEL文..
  • ASP简介
  • 用ASP发送邮件
  • ASP如何获取真实IP地址
  • 动网论坛超级安装指南,新新人..
  • Flash和ASP实现的用户登录/注..
  • 在线实时开通WEB及FTP源程序
  • LINE 的计数器源程序(附源代..
  • 聊天室实现私聊(一)
  • 用VB编写ActiveX DLL实现ASP..
  • 利用ASP在线维护数据库
  • asp中利用数组实现数据库记录..
  • 其它的ASP常用组件
  • ASP应用之模板采用
 
 

ASP操作XML的类

  • 日期:2008-03-08     人气:     出处:本站     作者:
  • 字体大小:
  • 小
  • 中
  • 大

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")

<%
dim xml,xmlfile
xmlfile="/Person/3/7/fls975/blog.xml"
set xml=new QT_XML_Class

Class QT_XML_Class
'Projict : ASP操作XML
'Author : Missde
'Link : www.missde.cn
'Date : 15:25 2007-5-29
private dom,xmlpath,doc
Public iserr_
'初始化类
Private Sub Class_Initialize()
Set dom = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
xmlpath = Server.MapPath(xmlfile)
If not dom.Load(xmlpath) Then
SaveToFile "<?xml version=""1.0"" encoding=""utf-8""?>"&vbcrlf&"<blog>"&vbcrlf&"<sorts>"&vbcrlf&"</sorts>"&vbcrlf&"<blogs>"&vbcrlf&"</blogs>"&vbcrlf&"<re>"&vbcrlf&"</re>"&vbcrlf&"</blog>",xmlpath

网页教学网


dom.Load(xmlpath)
End If
end Sub

Private Sub Class_Terminate
If IsObject(dom) Then Set dom = Nothing
If IsObject(doc) Then Set doc = Nothing
End Sub

Private Function SaveToFile(ByVal strBody,ByVal SavePath)
dim ado
Set ado = Server.CreateObject("ADODB.Stream")
ado.Open
ado.Type = 2
ado.charset = "utf-8"
ado.WriteText strBody
ado.SaveToFile SavePath,2
ado.Close
Set ado = Nothing
End Function

function d_node(node)
iserr_=False
set doc=dom.documentElement.selectSingleNode(node)
if not doc is nothing then
doc.parentNode.removeChild(doc)
dom.save(xmlpath)
iserr_=True
end if
set doc=nothing
End Function

function d_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).parentNode.removeChild(doc.item(i))
next
iserr_=True
end if
Webjx.Com

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
%>

相关文章
  • php教程:mysql数据库操作的DB类
  • 关于XML在FLASH中的应用
  • 操作Vista系统的回收站的一些技巧
  • ASP关于类的Let,Set和Get的用法的异同
  • ASP操作XML文件的主要方法和实现
  • asp控制xml数据库的6段代码
  • ASP对XML文档中文本的增加、删除、修改、查看
  • ASP教程:ASP关于数组的应用技巧
  • ASP是不是值得学习呢?
  • 教程:Asp.net与Xml开发网络硬盘技术
相关软件

  • 网友评论:
  • 查看所有评论
  • 我要发表评论
 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 加入收藏 | 帮助中心 |

Copyright © 2006-2007 fwvv.net  程序支持:木翼  皖ICP备06004916号  

感谢:点击网络 联网科技 天盈信息  提供服务器及带宽赞助