Complete the asp language to add, delete, modify, and view the specified node text in the XML document. Friends in need can refer to it. Copy the code code as follows:
<%
'------------------------------------------------ ---------------
'Program introduction: Complete the asp language to add, delete, modify and view the text of the specified node in the XML document
'Entry parameters: None
'Export parameters: None
'------------------------------------------------
'Function name: ConnectXml()
'Entry parameters: filename xml file name to be connected or opened
'Export parameters: None
'Return value: ConnectXml=0, XMLMorntekDocument is an object that successfully loads the XML document.
'ConnectXml<>0, then print the error message 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
'------------------------------------------------
'Function name: CloseXml()
'Entry parameters: None
'Export parameters: None
'------------------------------------------------
function CloseXml(XMLMorntekDocument)
if IsObject(XMLMorntekDocument) then
set XMLMorntekDocument=nothing
end if
end function
'------------------------------------------------
'Function name: SelectXmlNodeText(elementname)
'Entry parameter: elementname The name of the element
'Export parameters: None
'------------------------------------------------
function SelectXmlNodeText(elementname)
elementname=//&elementname
temp=XMLMorntekDocument.selectSingleNode(elementname).text
selectXmlNodeText= server.htmlencode(temp)
end function
'------------------------------------------------
'Function name: InsertXmlNodeText(befelementname,elementname,elementtext)
'Entry parameter: elementname The name of the inserted element
' befelementname inserts an element before the name of this element
'elementtext The text of the inserted element
'Export parameters: None
'------------------------------------------------
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
'------------------------------------------------
'Function name: UpdateXmlNodeText(elementname,newelementtext)
'Entry parameter: elementname The name of the element
' The new text of the newelementtext element
'Export parameters: None
'------------------------------------------------
function UpdateXmlNodeText(elementname,newelementtext)
dim element
set element=XMLMorntekDocument.selectSingleNode(//&elementname)
element.text=newelementtext
end function
'------------------------------------------------
'Function name: DeleteXmlNodeText(elementname)
'Entry parameter: elementname The name of the element
'Export parameters: None
'------------------------------------------------
function DeleteXmlNodeText(elementname)
XMLMorntekDocument.selectSingleNode(//&elementname).text =
end function
%>