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.