Error: XML page cannot be displayed, the following tags are not closed workaround _xml Foundation

Source: Internet
Author: User
Read the data from the database, and then display the data in XML format, but prompted Hd,category,subsort and so did not close, but I have closed ah, I do not know what is the specific reason for this problem?
VB Code:
Copy Code code as follows:

<%
Response. Contenttype= "Text/xml"
Response.Charset = "GB2312"
Response.Expires = 0
Response.Write "<?xml Versio N= "1.0" "encoding=" UTF-8 "?>"
Response.Write vbcrlf& " Response.Write vbcrlf&vbtab& amp; " <category>
Response.Write vbcrlf&vbtab&vbtab& <subsort>
' Connect to the database ' omit
Do while n OT rs.eof
Response.Write vbcrlf&vbtab&vbtab&vbtab& "<item>"
Response.Write vbcrlf& vbtab&vbtab&vbtab&vbtab& "<id>" &rs ("id") & "</id>"
Response.Write vbCrLf &vbTab&vbTab&vbTab& </item>
Loop
Rs.close ()
Set rs=nothing
Response.Write V bcrlf&vbtab&vbtab& "</subsort>"
Response.Write vbcrlf&vbtab& "</category>"
Response.Write vbcrlf& " Response.End ()
%>

Because the output can not take <> "' & these special characters, you need to xmlencode coding, such as the following code details:
VBScript Code:
Copy Code code as follows:

Function Xmlencode (Var)
On Error Resume Next
Dim strtmp
If (IsNull (Var)) Then
var = ""
End If
If (VarType (var) = one) Then
If (Var) Then
strtmp = "1"
Else
Strtmp = "0"
End If
Else
strtmp = CStr (Var)
strtmp = Replace (strtmp, "&", "&")
strtmp = Replace (strtmp, "<", "<")
strtmp = Replace (strtmp, ">", ">")
strtmp = Replace (strtmp, "" "", "" ")
strtmp = Replace (strtmp, "'", "")
End If
Xmlencode = strtmp
End Function
Function Xmldecode (str)
Dim Temp
Temp=replace (str, "&", "&")
Temp=replace (temp, "<", "<")
Temp=replace (temp, ">", ">")
Temp=replace (temp, "" "," "" ")
Temp=replace (temp, "'", "" ")
Xmldecode = Temp
End Function
Response.Write Xmlendode (RS ("field name")

In addition, if it is a file encoding problem, you can:
Response.Write "<?xml version=" "1.0″" encoding= "" Utf-8″ "?>"
Change into
Response.Write "<?xml version=" "1.0″" encoding= "" Gb2312″ "?>"
In addition, the content needs to be emptied before the output is started:
Response.Clear
Response.Write "<?xml version=" "1.0″" encoding= "" Gb2312″ "?>"
In addition, write:
Response.Write VbCrlf & VbTab & VbTab & "<subsort>"
more easily observed.

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.