Description of the ASP's classes that manipulate XML:
Can complete the ASP to the XML node add, delete, modify, empty.
For the above operation, according to the conditions, the operation type includes: Only the first one meets the condition, and all conforms to the condition two kinds.
Such as:
' Replace the first condition value with the new value
' Call Xml.r_node ("/blog/sorts/sort[id= ' 2 ']/name", "Lei2")
' Replace all conditional values with new values
' 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 operation XML
' Author:missde
' Link:www.missde.cn
' Date:15:25 2007-5-29
Private Dom,xmlpath,doc
Public Iserr_
' Initialize class
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 Web Teaching Network
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 are 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 are nothing Then
For I=0 to Doc.length-1
Doc.item (i). Parentnode.removechild (Doc.item (i))
Next
Iserr_=true
End If
Web Teaching Network
Dom.save (Xmlpath)
Set doc=nothing
End Function
function C_node (node)
Iserr_=false
Set Doc=dom.documentelement.selectsinglenode (node)
If not doc are 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 are 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 are nothing Then
iserr_=true
Set newxml = Serve R.createobject ("Microsoft.XMLDOM")
Newxml.loadxml (XMLSTR&VBCRLF)
Set rootnewnode= Newxml.documentelement Web page Teaching Network
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 no 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 are nothing Then
for i=0 to Doc.length-1
Doc.item (i). Text=newstr
Next
iserr_=true
End I F
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 are nothing then
if does C.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 are 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 are 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
Webjx.com
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
%>
Keywords: asp.net operation xml ASP operation XML ASP Operation database class ASP database operation class ASP XML asp.net XML ASP xmlhttp ASP to generate XML asp.net xmlhttp ASP output XML