C # version RSS reader (new read OPML function)

xiaoxiao2021-03-05  30

C # version RSS reader (new read OPML function)

Add a TreeView control to display the read OPML results. I am now known to have OPML. And its OPML is not a unified format, so you have to add a judgment (blue part) in the loadopml () method, not cool! Oh ... maybe it hasn't formed a standard, maybe it will not be so troubleson in the future.

New source code (part): private void loadopml (string url) {this.statusbar1.text = " THISTBOX1.TEXT " and check ... "; this.LoadXml2coach (this.TextBox1.text ); This.statusbar1.text = "OPML related information is being read ..."; this.loadopml (); this.statusbar1.text = "Finish";} private void loadopml () {xmlDocument doc = new xmldocument (); doc .Load (this.rssfullpath); xmlnodelist nodelist; nodelist = doc.selectNodes ("/ opml / body / outline); if (nodelist [0] .haschildnodes) {nodelist = doc.selectnodes (" / opml / body / Outline / OUTLINE ");} this.treeView1.nodes.clear (); for (int i = 0; i

) {IF (this.TreeView1.SelectedNode.Text.Equals (Nodelist [i] .attributes.getnamedItem ("Title"). InnerText)) {url = nodelist [i] .attributes.getnamedItem ("XMLURL"). InnerText; }}} This.LoadRSS (URL);}} private void loadrss (String URL) {this.statusbar1.text = "" URL "and check ..."; this.loadxml2coach (URL); this.statusbar1 .Text = "BLOG related information is being read ..."; this.LoadTitle (); this.statusbar1.text = "Read RSS content information ..."; this.LoadItem (); this.statusbar1.text = "Finish" } C # Edition Simple RSS Reader. by

VB version is completed, thankink to technical support!

Source code:

Using system;

Using system.drawing;

Using system.collections;

Using system.componentmodel;

Using system.windows.forms;

Using system.data;

USING SYSTEM.XML;

Using system.io;

Using system.threading;

Namespace YulrsSreader

{

///

/// Form1 summary description.

///

Public Class Form1: System.Windows.Forms.form

{

Private system.windows.Forms.Label label1;

Private system.windows.Forms.Label label2;

Private system.windows.Forms.Label label3;

Private system.windows.Forms.TextBox textBox1;

Private system.windows.Forms.Button button1;

Private system.windows.Forms.Label Blogname;

Private system.windows.forms.label blockdescription;

Private system.windows.forms.listbox listbox1;

Private system.windows.Forms.statusbar statusbar1;

Private axshdocvw.axwebbrowser AxwebBrowser1;

///

/// The required designer variable.

///

Private system.componentmodel.Container Components = NULL;

Public form1 () {

//

// Windows Form Designer Support

//

InitializationComponent ();

//

// Todo: Add any constructor code after INITIALIZECOMPONENT call

//

}

///

/// Clean all the resources being used.

///

Protected Override Void Dispose (Bool Disposing)

{

IF (Disposing)

{

IF (Components! = NULL)

{

Components.dispose ();

}

}

Base.dispose (Disposing);

}

#Region Windows Form Designer Generated Code

///

/// Designer supports the required method - do not use the code editor to modify

/// This method is content.

///

Private vidinitiRizeComponent ()

{

System.Resources.ResourceManager Resources = New System.Resources.ResourceManager (TypeOf (Form1));

THIS.LABEL1 = New System.windows.Forms.label ();

THIS.LABEL2 = New System.windows.Forms.label ();

This.label3 = new system.windows.Forms.label ();

This.TextBox1 = new system.windows.Forms.TextBox ();

This.button1 = new system.windows.Forms.Button ();

This.blogname = new system.windows.forms.label ();

THIS.BLOGDESCRIPTION = New System.windows.Forms.label ();

This.listbox1 = new system.windows.forms.listbox ();

This.statusbar1 = new system.windows.Forms.statusbar ();

THIS.AXWebBrowser1 = new axshdocvw.axwebbrowser ();

(System.comPonentModel.isupportInitialize) (this.Axwebbrowser1)). Begininit ();

THIS.SUSPENDLAYOUT ();

//

// label1

//

THIS.LABEL1.LOCATION = New System.drawing.Point (8, 8);

THIS.LABEL1.NAME = "label1";

This.label1.size = new system.drawing.size (64, 23);

this.label1.tabindex = 0;

This.Label1.Text = "RSS address:";

//

// label2

//

This.Label2.Location = new system.drawing.point (8, 40);

THIS.LABEL2.NAME = "label2";

This.label2.size = new system.drawing.size (64, 23);

THIS.Label2.tabindex = 1;

THIS.LABEL2.TEXT = "blog:"; //

// label3

//

THIS.Label3.Location = new system.drawing.point (8, 72);

THIS.LABEL3.NAME = "label3";

THIS.Label3.size = new system.drawing.size (64, 23);

THIS.Label3.tabindex = 2;

This.Label3.Text = "Description:";

//

// textbox1

//

This.TextBox1.Location = new system.drawing.point (72, 8);

THIS.TEXTBOX1.NAME = "TextBox1";

THIS.TEXTBOX1.SIZE = New System.drawing.size (392, 21);

This.TextBox1.tabindex = 3;

THIS.TEXTBOX1.TEXT = "";

//

// Button1

//

This.Button1.Location = new system.drawing.point (472, 16);

This.button1.name = "button1";

This.button1.size = new system.drawing.size (80, 64);

this.button1.tabindex = 4;

This.Button1.Text = "Read";

This.Button1.click = new system.eventhandler (this.button1_click);

//

// blogname

//

This.blogname.location = new system.drawing.point (72, 40);

this.blogname.name = "blogname";

this.blogname.size = new system.drawing.size (392, 23);

this.blogname.tabindex = 5;

//

// blogDescription

//

This.blogdescription.Location = new system.drawing.point (72, 72);

this.blogdescription.name = "blogdescription";

This.blogdescription.size = new system.drawing.size (392, 23);

this.blogdescription.tabindex = 6;

//

// ListBox1

//

THISTBOX1.ItemHeight = 12;

This.listbox1.location = new system.drawing.point (0, 104);

this.listbox1.name = "listbox1";

this.listbox1.size = new system.drawing.size (560, 112);

THISLISTBOX1.TABINDEX = 7;

This.listbox1.selected = new system.eventhandler (this.listbox1_selected); //

// statusbar1

//

This.statusbar1.Location = new system.drawing.point (0, 591);

THIS.STATUSBAR1.NAME = "statusbar1";

THIS.STATUSBAR1.SIZE = New System.drawing.size (562, 22);

this.statusbar1.tabindex = 8;

//

// AxWebBrowser1

//

this.axwebbrowser1.dock = system.windows.Forms.dockStyle.bottom

THIS.AXWebBrowser1.enabled = True;

THIS.AXWebBrowser1.Location = new system.drawing.point (0, 223);

THIS.AXWebBrowser1.ocxState = ((System.Windows.Forms.Axhost.State) ("AxWebBrowser1.OCxState)));

This.axwebbrowser1.size = new system.drawing.size (562, 368);

THIS.AXWebBrowser1.tabindex = 9;

//

// Form1

//

THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);

THIS.CLIENTSIZE = New System.drawing.size (562, 613);

This.Controls.add (this.axwebbrowser1);

This.Controls.add (this.statusbar1);

This.Controls.add (this.listbox1);

This.Controls.add (this.blogdescription);

This.Controls.add (this.blogname);

This.Controls.add (this.button1);

This.Controls.add (this.TextBox1);

THIS.CONTROLS.ADD (this.label3);

THIS.CONTROLS.ADD (this.label2);

This.Controls.add (this.label1);

This.FormBorderstyle = system.windows.Forms.FormBorderstyle.FixedSingle;

THIS.NAME = "Form1";

This.startPosition = system.windows.forms.formstartPosition.CenterScreen

THIS.TEXT = "Yul / 's rss reader";

This.Load = New System.EventHandler (this.form1_load);

(System.comPonentModel.isupportInitialize) (this.axwebbrowser1)). Endinit ();

This.ResumeLayout (false);

}

#ndregion

///

/// The main entry point for the application.

/// [stathread]

Static void main ()

{

Application.run (New Form1 ());

}

Private Void Form1_Load (Object Sender, System.EventArgs E)

{

THIS.AXWebBrowser1.width = this.width;

this.statusbar1.text = "Ready";

}

PRIVATE Thread thread;

Private string filefullpath = application.startuppath "~ tempdoc.xml";

Private void loadingrss ()

{

THIS.STATUSBAR1.TEXT = "Read" this.TextBox1.text "and check ...";

This.LoadXml2Coach (THISTEXTBOX1.TEXT);

This.statusbar1.text = "BLOG related information is being read ...";

THISLOADTITLE ();

This.statusbar1.text = "Reads RSS content information ...";

This.LoadItem ();

This.statusbar1.text = "Complete";

}

Private void loadingXML2COACH (String URL)

{

XmLDocument Doc = New XmLDocument ();

Doc.Load (URL);

Doc.save (this.filefullpath);

}

Private void loadingTitle ()

{

XmLDocument Doc = New XmLDocument ();

Doc.Load (this.filefullpath);

XMLNodelist NodeList;

Nodelist = Doc.selectNodes ("/ RSS / CHANNEL");

This.blogname.text = nodelist [0] .selectsinglenode ("Title"). innerText;

This.blogdescription.text = nodelist [0] .selectsinglenode ("description"). innerText;

}

Private void loadItem ()

{

XmLDocument Doc = New XmLDocument ();

Doc.Load (this.filefullpath);

XMLNodelist NodeList;

Nodelist = Doc.selectNodes ("/ RSS / Channel / Item");

This.listbox1.items.clear ();

XMLNameSpaceManager ns = new xmlnamespacemanager (doc.nametable);

ns.addNameSpace ("DC", "http://purl.org/dc/elements/1.1/");

Try

{

For (INT i = 0; i

{

THISTBOX1.Items.Add ("[" nodelist [i] .selectsinglenode ("DC: Creat", NS) .innertext "]" Nodelist [i] .selectsinglenode ("title"). InnerText);}

}

Catch (Exception EX)

{

Messagebox.show (ex.totring ());

}

}

Private void loadinghtml ()

{

XmLDocument Doc = New XmLDocument ();

Doc.Load (this.filefullpath);

XMLNodelist NodeList;

Nodelist = Doc.selectNodes ("/ RSS / Channel / Item");

Bool flag;

String temp = "";

String content = "";

THIS.STATUSBAR1.TEXT = "Reads article content ...";

XMLNameSpaceManager ns = new xmlnamespacemanager (doc.nametable);

ns.addNameSpace ("DC", "http://purl.org/dc/elements/1.1/");

For (INT i = 0; i

{

Temp = "[" nodelist [i] .selectsinglenode ("DC: CREATOR", NS) .INNNERTEXT "]" nodelist [i] .selectsinglenode ("title"). innerText;

IF (this.listbox1.selecteditem.tostring (). Equals (temp))

{

Content = Content

Content = Content

Title:

Content = Content Nodelist [i] .selectsinglenode ("Title"). innerText;

content = content "
OF: ";

Content = Content Nodelist [i] .selectsinglenode ("DC: Creat", NS) .INNNNERTEXT; Content = Content " ";

Content = Content Nodelist [i] .selectsinglenode ("description"). innerText;

Content = Content " ";

Flag = SavetextFile (Application.Startuppath "~ Temp.html", Content;

Object flags = 0;

Object targetframe = string.empty;

Object poster = string.empty;

Object headers = String.empty;

This.axwebbrowser1.navigate (Application.Startuppath "~ Temp.html", Ref Flags, Ref TargetFrame, Ref PostData, Ref Headers;

Break;

}

}

This.statusbar1.text = "Complete";

}

Private Bool SavetextFile (String FilePath, String FileContent)

{

System.io.StreamWriter SW = NULL;

Try

{

SW = New streamwriter (FilePath, False);

SW.WRITE (FileContent);

Return True;

}

Catch (Exception EX)

{

Messagebox.show (ex.totring ());

Return False;

}

Finally

{

IF (sw! = null)

SW.CLOSE ();

}

}

Private void Button1_Click (Object Sender, System.Eventargs E)

{

Try

{

THIS.THREAD = New Thread (New ThreadStart (this.LoadRSS);

THIS.THREAD.START ();

}

Catch (Exception EX)

{

Messagebox.show (ex.totring ());

}

}

Private void ListBox1_selectedIndexchanged (Object Sender, System.Eventargs E)

{

Try

{

THIS.THREAD = New Thread (New ThreadStart (this.loadHtml);

THIS.THREAD.START ();

}

Catch (Exception EX)

{

Messagebox.show (ex.totring ());

}

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-34445.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.033, SQL: 9