完成asp語言對XML文檔中指定節點文本的增加、刪除、修改、查看

來源:互聯網
上載者:User


<%
'----------------------------------------------------------------
'程式簡介: 完成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
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.