<!– metadata type="typelib" uuid="00000200-0000-0010-8000-00aa006d2ea4" –>
<%
class dataset
private recordset
public tablename, fieldcount
public xmlstring
private tablemap
private sub class_initialize 设置 initialize 事件。
set recordset = server.createobject("adodb.recordset")
recordset.activeconnection = "provider=msdaosp; data source=msxml2.dsocontrol;"
end sub
private sub class_terminate 设置 terminate 事件。
set recordset = nothing
end sub
function readxml(name, filespec)
tablename = name
recordset.open(filespec)
end function
function getxml()
call gettablemap()
do while not recordset.eof
xmlstring = xmlstring + getxmlrow(recordset.fields)
recordset.movenext()
loop
recordset.close
xmlstring = xmlrow(tablename, xmlstring)
getxml = xmlstring
end function
sub gettablemap()
if (not recordset.eof) then
fieldcount = recordset.fields.count – 2
execute("redim tablemap("& fieldcount &")")
for i = 0 to fieldcount
tablemap(i) = recordset.fields.item(i).name
next
end if
end sub
function getxmlrow(item)
dim xmlrowstring
for i = 0 to fieldcount
xmlrowstring = xmlrowstring + xmlfield(tablemap(i), item(i).value)
next
getxmlrow = xmlrow("row", xmlrowstring)
end function
function xmlencode(xmlstring)
xmlstring = replace(xmlstring, "<", "<")
xmlstring = replace(xmlstring, ">", ">")
xmlencode = xmlstring
end function
function xmlfield(nodename, nodevalue)
xmlfield = "<"+ nodename +">"+ xmlencode(nodevalue) +"</"+ nodename +">"
end function
function xmlrow(nodename, nodevalue)
xmlrow = "<"+ nodename +">"+ nodevalue +"</"+ nodename +">"
end function
end class
dim ds : set ds = new dataset
call ds.readxml( "news", server.mappath("news.xml") )
response.contenttype = "text/xml"
response.write(ds.getxml())
set ds = nothing
%>
