RSS Data Source Creation

Source: Internet
Author: User

Public class RSS
{
Public String title;
Public String image_title;
Public String image_link;
Public String image_url;
Public String description;
Public String link;
Public String language;
Public String generator;
Public String TTL;
Public String copyright;
Public String pubdate;
Public String category;

Public RSS ()
{}
Public RSS (string stitle, string simage_title, string simage_link, string simage_url, string sdescription,
String Slink, string slanguage, string sgenerator, string sttl, string scopyright, string spubdate, string scategory)
{
Title = stitle;
Image_title = simage_title;
Image_link = simage_link;
Image_url = simage_url;
Description = sdescription;
Link = slink;
Language = slanguage;
Generator = sgenerator;
TTL = sttl;
Copyright = scopyright;
Pubdate = spubdate;
Category = scategory;
}
Public void create_xml (string filename, dataset ds, string HTTP)
{
Xmldocument Doc = new xmldocument (); // Add a header Node

Xmldeclaration delinoleic = Doc. createxmldeclaration ("1.0", "UTF-8", "no ");
Doc. appendchild (decia );

Xmlelement stitle = Doc. createelement ("title ");
Stitle. innertext = title;
Xmlelement simage_title = Doc. createelement ("title ");
Simage_title.innertext = image_title;
Xmlelement simage_link = Doc. createelement ("Link ");
Simage_link.innertext = image_link;
Xmlelement simage_url = Doc. createelement ("url ");
Simage_url.innertext = image_url;

Xmlelement sdescription = Doc. createelement ("Description ");
Sdescription. innertext = description;
Xmlelement slink = Doc. createelement ("Link ");
Slink. innertext = link;
Xmlelement slanguage = Doc. createelement ("language ");
Slanguage. innertext = language;
Xmlelement sgenerator = Doc. createelement ("generator ");
Sgenerator. innertext = generator;

Xmlelement sttl = Doc. createelement ("TTL ");
Sttl. innertext = TTL;
Xmlelement scopyright = Doc. createelement ("Copyright ");
Scopyright. innertext = copyright;
Xmlelement spubdate = Doc. createelement ("pubdate ");
Spubdate. innertext = pubdate;
Xmlelement scategory = Doc. createelement ("category ");


Xmlelement image = Doc. createelement ("image ");

Xmlelement RSS = Doc. createelement ("RSS ");
Doc. appendchild (RSS );
Xmlattribute version = Doc. createattribute ("version ");
Version. value = "2.0 ";
RSS. Attributes. append (version );

Xmlelement channel = Doc. createelement ("channel ");
RSS. appendchild (Channel );
Channel. appendchild (stitle );
Channel. appendchild (image );
Image. appendchild (simage_title );
Image. appendchild (simage_link );
Image. appendchild (simage_url );
Channel. appendchild (sdescription );
Channel. appendchild (slink );
Channel. appendchild (slanguage );
Channel. appendchild (sgenerator );
Channel. appendchild (sttl );
Channel. appendchild (scopyright );
Channel. appendchild (spubdate );
Channel. appendchild (scategory );

Foreach (datarow row in DS. Tables [0]. Rows)
{
Xmlelement item = Doc. createelement ("item ");

Xmlelement sstitle = Doc. createelement ("title ");
Sstitle. innertext = row ["title"]. tostring ();

Xmlelement sslink = Doc. createelement ("Link ");
Sslink. innertext = http + row ["ID"]. tostring ();

Xmlelement author = Doc. createelement ("author ");
Author. innertext = row ["username"]. tostring ();

Xmlelement guid = Doc. createelement ("guid ");
Guid. innertext = http + row ["ID"]. tostring ();

Xmlelement sscategory = Doc. createelement ("category ");
Sscategory. innertext = string. empty;

Xmlelement sspubdate = Doc. createelement ("pubdate ");
Sspubdate. innertext = row ["datetime"]. tostring ();

Xmlelement comment = Doc. createelement ("comment ");
Comment. innertext = string. empty;

Xmlelement ssdescription = Doc. createelement ("Description ");
Ssdescription. innertext = row ["title"]. tostring ();

Channel. appendchild (item );

Item. appendchild (sstitle );
Item. appendchild (sslink );
Item. appendchild (author );
Item. appendchild (guid );
Item. appendchild (sscategory );
Item. appendchild (sspubdate );
Item. appendchild (comment );
Item. appendchild (ssdescription );

}

Doc. Save (filename );

}
}

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.