ASP generates XML

Source: Internet
Author: User
The code is as follows Copy Code

<%
Dim Rs,sql,foundstr
Dim Classid,childstr
Dim Rssbody,rsstitle,rsshomepageurl
Dim Xmldom,node,cnode,cnode1,msginfo
Set xmldom = Server.CreateObject ("Microsoft.FreeThreadedXMLDOM")
Xmldom.appendchild (xmldom.createelement ("RSS"))
XMLDOM.documentElement.attributes.setNamedItem (Xmldom.createnode (2, "Version", "")). text= "2.0"
Set node = XMLDOM.documentElement.appendChild (Xmldom.createnode (1, "channel", ""))
Rsshomepageurl = Newasp.siteurl
Rsstitle = "Get List of articles"
ClassID = Newasp.checknumeric (Request ("ClassID"))

Dim Channelrootdir
Channelrootdir = Newasp.installdir & Newasp.channeldir

Sub xmlarticlelist ()
Dim Specialid,stype
If Trim (Request ("Specialid")) <> "Then
Specialid = Newasp.checknumeric (Request ("Specialid"))
Specialid = CLng (specialid)
If specialid = 0 Then
Foundstr = "and a.specialid>0 order by A.writetime DESC, A.articleid DESC"
Else
Foundstr = "and a.specialid=" & Specialid & "ORDER by A.writetime DESC, A.articleid DESC"
End If
Else
If classid > 0 Then
SQL = "Select Classname,childstr from [nc_classify] WHERE channelid =" & Channelid & "and classid=" & CLng (c LASSID)
Set Rs = Newasp.execute (SQL)
If Rs.bof and Rs.eof Then
Set Cnode=node.appendchild (Xmldom.createnode (1, "Item", ""))
Cnode.appendchild (Xmldom.createnode (1, "title", "")). text= "no article classification found"
Cnode.appendchild (Xmldom.createnode (1, "link", "")). Text=rsshomepageurl
Cnode.appendchild (Xmldom.createnode (1, "Author", "")). Text=newasp.sitename
Cnode.appendchild (Xmldom.createnode (1, "pubdate", "")). Text=now ()
Set Cnode1=cnode.appendchild (Xmldom.createnode (1, "description", ""))
Msginfo= "did not find article classification!" "
Cnode1.appendchild (Xmldom.createcdatasection (Msginfo))
Rs.Close:Set Rs = Nothing
Exit Sub
Else
Rsstitle = Rs ("ClassName")
Childstr = Rs ("Childstr")
End If
Rs.Close:Set Rs = Nothing
Foundstr = "and A.classid in (" & Childstr & ") Order by A.writetime DESC, A.articleid DESC"
Else
Rsstitle = "All articles list"
Foundstr = "ORDER by A.writetime DESC, A.articleid DESC"
End If
End If
If Trim (Request ("type")) <> "Then
stype = Newasp.checknumeric (Request ("type")
stype = CInt (stype)
If stype = 0 Then
Foundstr = Replace (Foundstr, "A.writetime", "A.allhits")
Else
Foundstr = "and isbest>0" & Foundstr
End If
End If
Node.appendchild (Xmldom.createnode (1, "title", "")) .text=newasp.sitename& "--" &rsstitle
Node.appendchild (Xmldom.createnode (1, "link", "")). Text=newasp.siteurl
Node.appendchild (Xmldom.createnode (1, "Language", "")). text= "ZH-CN"
Node.appendchild (Xmldom.createnode (1, "description", "")). Text=newasp.sitename
Node.appendchild (Xmldom.createnode (1, "Copyright", "")). Text=newasp.siteurl
Node.appendchild (Xmldom.createnode (1, "Generator", "")). text= "Rss Generator by Newasp.net"

Dim Htmlfilename,htmlfileurl
SQL = "A.articleid,a.classid,a.title,a.content,a.writetime,a.htmlfiledate,a.author,"
sql = "SELECT top" & SQL & C.classname,c.htmlfiledir,c.usehtml,b.channeldir,b.stopchannel,b.modulename,b. Iscreatehtml,b.htmlextname,b.htmlpath,b.htmlform,b.htmlprefix from ([nc_article] A INNER JOIN [nc_classify] C on A. CLASSID=C.CLASSID) INNER JOIN [Nc_channel] B on A.channelid=b.channelid WHERE a.isaccept>0 and a.channelid= "& CLng (channelid) & "& Foundstr &" "
Set Rs = Newasp.execute (SQL)
If Rs.bof and Rs.eof Then
Set Cnode=node.appendchild (Xmldom.createnode (1, "Item", ""))
Cnode.appendchild (Xmldom.createnode (1, "title", "")). text= "No articles found"
Cnode.appendchild (Xmldom.createnode (1, "link", "")). Text=rsshomepageurl
Cnode.appendchild (Xmldom.createnode (1, "Author", "")). Text=newasp.sitename
Cnode.appendchild (Xmldom.createnode (1, "pubdate", "")). Text=now ()
Set Cnode1=cnode.appendchild (Xmldom.createnode (1, "description", ""))
Msginfo= "did not find the article!" "
Cnode1.appendchild (Xmldom.createcdatasection (Msginfo))
Rs.Close:Set Rs = Nothing
Exit Sub
Else
Do as not rs.eof
Htmlfilename = Newasp.readfilename (rs ("Htmlfiledate"), RS ("ArticleID"), RS ("Htmlextname"), RS ("Htmlprefix"), RS (" HtmlForm ")," "")
If Rs ("iscreatehtml") <> 0 Then
Htmlfileurl = Showchannelpath (Channelrootdir,rs ("Htmlfiledir")) & Newasp.showdatepath (RS ("Htmlfiledate"), RS (" Htmlpath ")) & Htmlfilename
Else
Htmlfileurl = Newasp.getchanneldir (channelid) & "Show.asp?id=" & Rs ("ArticleID")
End If
If LCase (Left (htmlfileurl,7)) <> "http://" Then Htmlfileurl = rsshomepageurl & Htmlfileurl
Set Cnode=node.appendchild (Xmldom.createnode (1, "Item", ""))
Cnode.appendchild (Xmldom.createnode (1, "title", "")). Text=replace (Rs ("title"), "&nbsp;", "" "
Cnode.appendchild (Xmldom.createnode (1, "link", "")). Text=htmlfileurl
Cnode.appendchild (Xmldom.createnode (1, "category", "")). Text=rs ("ClassName")
Cnode.appendchild (Xmldom.createnode (1, "Author", "")). Text=rs ("author")
Cnode.appendchild (Xmldom.createnode (1, "pubdate", "")). Text=rs ("Writetime")
Set Cnode1=cnode.appendchild (Xmldom.createnode (1, "description", ""))
msginfo= newasp.cutstring (Rs ("Content"), 300)
Cnode1.appendchild (Xmldom.createcdatasection (Msginfo))
Rs.movenext
Loop
End If
Rs.Close:Set Rs = Nothing
End Sub

Sub Showxml ()
Response.Clear
response.charset= "gb2312"
Response.contenttype= "Text/xml"
Response.Write "<?xml version=" "1.0" "encoding=" "gb2312" "?>" &vbnewline
Response.Write Xmldom.xml
Set xmldom=nothing
End Sub

Xmlarticlelist ()
Showxml ()
Closeconn
%>

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.