Complete instance code for ASP to operate XML files

Source: Internet
Author: User

Copy codeThe Code is as follows: <%
'----------------------------------------------------------------
'Program Introduction: added, deleted, modified, and viewed the specified node text in the XML document in asp.
'Entry parameter: None
'Exit parameter: None
'------------------------------------------------
'Function name: ConnectXml ()
'Entry parameter: the xml file name to be connected or opened by filename
'Exit parameter: None
'Return value: ConnectXml = 0. XMLMorntekDocument is an object that successfully loads the XML document.
'Connectxml <> 0, the error message strError is printed.
'------------------------------------------------
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 = "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 parameter: None
'Exit parameter: None
'------------------------------------------------
Function CloseXml (XMLMorntekDocument)
If IsObject (XMLMorntekDocument) then
Set XMLMorntekDocument = nothing
End if
End function

'------------------------------------------------
'Function name: SelectXmlNodeText (elementname)
'Entry parameter: the name of the elementname Element
'Exit parameter: None
'------------------------------------------------
Function SelectXmlNodeText (elementname)
Elementname = "//" & elementname
Temp = XMLMorntekDocument. selectSingleNode (elementname). text
SelectXmlNodeText = server.html encode (temp)

End function

'------------------------------------------------
'Function name: InsertXmlNodeText (befelementname, elementname, elementtext)
'Entry parameter: the name of the element inserted by elementname
'Befelementname: insert an element before the element name
'Elementtext: Text of the inserted element
'Exit parameter: 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: the name of the elementname Element
'Newelementtext
'Exit parameter: None
'------------------------------------------------
Function UpdateXmlNodeText (elementname, newelementtext)
Dim element
Set element = XMLMorntekDocument. selectSingleNode ("//" & elementname)
Element. text = newelementtext
End function

'------------------------------------------------
'Function name: DeleteXmlNodeText (elementname)
'Entry parameter: the name of the elementname Element
'Exit parameter: None
'------------------------------------------------
Function DeleteXmlNodeText (elementname)
XMLMorntekDocument. selectSingleNode ("//" & elementname). text = ""
End function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.