<%
'----------------------------------------------------------------
'程式簡介: 完成asp教程語言對xml文檔中指定節點文本的增加、刪除、修改、查看
'入口參數: 無
'出口參數: 無
'------------------------------------------------
'函數名字:connectxml()
'入口參數: filename 需要串連或開啟的xml檔案名稱
'出口參數: 無
'傳回值 :connectxml=0,xmlmorntekdocument就是一個成功裝載xml文檔的對象了。
' connectxml<>0,則列印錯誤資訊strerror
'------------------------------------------------
dim xmlmorntekdocument
function connectxml(filename)
dim strsourcefile
strsourcefile = server.mappath(filename)
set xmlmorntekdocument = server.createobject(" microsoft.xmldom")
xmlmorntekdocument.async = false
xmlmorntekdocument.load(strsourcefile)
connectxml=xmlmorntekdocument.parseerror.errorcode
if xmlmorntekdocument.parseerror.errorcode<>0 then
strerror="<h2>error"&xmlmorntekdocument.parseerror.errorcode&"</h2>"
strerror=strerror&xmlmorntekdocument.parseerror.reason&"<br>"
strerror=strerror&xmlmorntekdocument.parseerror.url&"<br>"
strerror=strerror&xmlmorntekdocument.parseerror.line&"<br>"
strerror=strerror&xmlmorntekdocument.parseerror.filepos&"<br>"
strerror=strerror&xmlmorntekdocument.parseerror.srctext&"<br>"
response.write strerror
end if
end function
'------------------------------------------------
'函數名字:closexml()
'入口參數: 無
'出口參數: 無
'------------------------------------------------
function closexml(xmlmorntekdocument)
if isobject(xmlmorntekdocument) then
set xmlmorntekdocument=nothing
end if
end function
'------------------------------------------------
'函數名字:selectxmlnodetext(elementname)
'入口參數: elementname 元素的名字
'出口參數: 無
'------------------------------------------------
function selectxmlnodetext(elementname)
elementname="//"&elementname
temp=xmlmorntekdocument.selectsinglenode(elementname).text
selectxmlnodetext= server.htmlencode(temp)
end function
'------------------------------------------------
'函數名字:insertxmlnodetext(befelementname,elementname,elementtext)
'入口參數: elementname 插入的元素的名字
' befelementname在此元素的名字前面插入元素
' elementtext 插入的元素的文本
'出口參數: 無
'------------------------------------------------
function insertxmlnodetext(befelementname,elementname,elementtext)
dim befelement,element
set befelement=xmlmorntekdocument.selectsinglenode("//"&befelementname)
set element= xmlmorntekdocument.createelement(elementname)
befelement.insertbefore element,befelement.firstchild
element.text=elementtext
end function
'------------------------------------------------
'函數名字:updatexmlnodetext(elementname,newelementtext)
'入口參數: elementname 元素的名字
' newelementtext元素的新文本
'出口參數: 無
'------------------------------------------------
function updatexmlnodetext(elementname,newelementtext)
dim element
set element=xmlmorntekdocument.selectsinglenode("//"&elementname)
element.text=newelementtext
end function
'------------------------------------------------
'函數名字:deletexmlnodetext(elementname)
'入口參數: elementname 元素的名字
'出口參數: 無
'------------------------------------------------
function deletexmlnodetext(elementname)
xmlmorntekdocument.selectsinglenode("//"&elementname).text =""
end function
%>