<%
'**************************************
'* 最后更新 2012-05-18 by 56770.Kingdge
'* Copyright www.56770.com
'**************************************
Class ASPXML
Private objDom,objnodes,objTable,Xml_Array,XMLnodes,ID,brstr,NewXMLnode,NewXMLcooky
Public Path,Data,Xml_Eof,Xml_Bof,Xml_Item,Xml_Count
Public Sub open()
On Error Resume Next 
set objDom=server.CreateObject("Microsoft.XMLDOM")
objDom.load Path
set objnodes=objdom.documentElement.SelectSingleNode("//"+Data+"").ChildNodes
set XMLnodes=objdom.documentElement.SelectSingleNode("//"+Data+"")
end sub
Public Function SelectTable(Table)
	objTable=Table
	Xml_Count=-1
	Xml_Eof=false
	Xml_Bof=false
	'Xml_Item=2
	if Xml_Item="" then
		Xml_Item=0
	end if
	GETCount()
	ChkCount()
end Function
Public Sub MoveNext()
	Xml_Item=Xml_Item+1
	ChkCount()
end sub
Public Sub MoveLast()
	Xml_Item=Xml_Item-1
	ChkCount()
end sub
Public Function Read(key)
	On Error Resume Next 
	Read=objnodes(int(Xml_Array(Xml_Item))).selectSingleNode(key).text
end Function
Public Function Write(key,viold)
	objnodes(int(Xml_Array(Xml_Item))).selectSingleNode(key).text=viold
end Function
Public Function SelectItem(key,viold)
	Xml_AllTableWords=""
	for i=0 to Xml_Count
		xml_viold=objnodes(int(Xml_Array(i))).selectSingleNode(key).text
		if xml_viold=viold then
			Xml_AllTableWords=Xml_AllTableWords+"|"+Xml_Array(i)
		end if
	next
	StrPtr = instr(Xml_AllTableWords, "|")
	Xml_AllTableWords = mid(Xml_AllTableWords, StrPtr+1)
	Xml_Array=split(Xml_AllTableWords , "|")
	Xml_Count=UBound(Xml_Array)
	ChkCount()
end Function
Public sub addnew()
	NewXMLnode=""
	if XMLnodes.hasChildNodes then
		ID = XMLnodes.lastchild.firstchild.text+1
	else
		'如是没有字子节点则是第一次留言ＩＤ号设为１
		ID=1
	end if
	brstr=chr(13)&chr(10)&chr(9)
	NewXMLcooky=brstr&"<"&objTable&">"&brstr &"<ID>"&ID&"</ID>"&brstr
end sub
Public Function add(key,viold)
	On Error Resume Next 
	NewXMLcooky=NewXMLcooky&"<"&key&">"&viold&"</"&key&">"&brstr
	NewXMLnode=NewXMLcooky&"</"&objTable&">"&chr(13)
end Function
Public Function delete(key,viold)
	for i=0 to Xml_Count
		if ISkeyOk(key,viold) then
			XMLnodes.removechild(objDom.selectsinglenode("//"&objTable&"["&key&"='"&viold&"']"))
		end if
	next
	objDom.save(Path)
end Function
Public Function deleteTable()
	for i=0 to Xml_Count
		XMLnodes.removechild(objDom.selectsinglenode("//"&objTable))
	next
	objDom.save(Path)
end Function
Public Sub update()
	if NewXMLnode<>"" then
		set objXML2=Server.CreateObject("Microsoft.XMLDOM")
		'建立一个新XML对像
		objXML2.loadXML(NewXMLnode)
		'把XML版片段读入内存中
		set rootNewNode=objXML2.documentElement
		'获得objXML2的根节点
		XMLnodes.appendChild(rootNewNode)
	end if
	objDom.Save(Path)
end sub
Public Sub CLOSE()
	set objnodes=nothing
	set objDom=nothing
	' Response.Write(objTable)
end sub
Private Function GETCount()
	On Error Resume Next 
	Xml_AllTableWords=""
	Xml_AllCount=-1
	for each element in objnodes
		Xml_AllCount=Xml_AllCount+1
		If element.nodename =objTable then
			Xml_AllTableWords=Xml_AllTableWords+"|"+cstr(Xml_AllCount)
		end if
	next
	StrPtr = instr(Xml_AllTableWords, "|")
	Xml_AllTableWords = mid(Xml_AllTableWords, StrPtr+1)
	Xml_Array=split(Xml_AllTableWords , "|")
	Xml_Count=UBound(Xml_Array)
end Function
Private Function ChkCount()
	if Xml_Count<0 then
		Xml_Bof=true
	end if
	if Xml_Item>Xml_Count then
		Xml_Eof=true
	end if
end Function
Private Function ISkeyOk(key,viold)
	ISkeyOk=false
	if not(XMLnodes.hasChildNodes) then
		exit Function
	end if
	for each timent in objnodes
		If timent.nodename =objTable then
			set pobjnodes=timent.ChildNodes
			for each yyment in pobjnodes
				if yyment.nodename=key and yyment.text=viold then
					ISkeyOk=true
					exit Function
				end if
			next
		end if
	next
end Function
End Class
%>