A few days ago, I was engaged in RSS analysis and encountered some problems.

Source: Internet
Author: User

RSS is now very popular and once popular on the Internet. Indeed, it has brought us great changes and convenience! There are also many RSS versions, including rss.1.0.rss2.0 and Atom!
I encountered a lot of problems when parsing, because I have not studied XML and related parsing work, so I have encountered a lot of problems and can successfully parse rss2.0 at present.
Some resolutions on the top (for now, I don't know what it is)

1 Private   Void Getrsshead (xmldocument DOC)
2 {
3 // Xmldocument Doc = new xmldocument ();
4 // Doc. loadxml (this. rssxmlstr );
5 Xmlelement ELEM = (Xmlelement) Doc. documentelement. firstchild;
6 This . Headtitle = ELEM. selectsinglenode ( " Title " ). Innertext;
7 This . Headurl = ELEM. selectsinglenode ( " Link " ). Innertext;
8 This . Headdescription = ELEM. selectsinglenode ( " Description " ). Innertext;
9
10 }

Content parsing:

1 Private   Void Parseitems ()
2 {
3 Xmldocument Doc =   New Xmldocument ();
4 Doc. loadxml ( This . Rssxmlstr );
5 Xmlnodelist nodelist;
6 Xmlelement Root = Doc. documentelement;
7 Nodelist = Root. getelementsbytagname ( " Item " );
8 For ( Int N = 0 ; N < Nodelist. Count; n ++ )
9 {
10 Listtitle. Add (nodelist [N]. selectsinglenode ( " Title " ). Innertext );
11 Listlink. Add (nodelist [N]. selectsinglenode ( " Link " ). Innertext );
12 Listdescription. Add (nodelist [N]. selectsinglenode ( " Description " ). Innertext );
13 }
14 }

However, for rss1.0, I can only handle this currently: 1 // Header
2 Nodelist = Root. getelementsbytagname ( " Channel " );
3 This . Headtitle = Nodelist [ 0 ]. Childnodes [ 0 ]. Innertext;
4 This . Headurl = Nodelist [ 0 ]. Childnodes [ 1 ]. Innertext;
5 This . Headdescription = Nodelist [ 0 ]. Childnodes [ 2 ]. Innertext;
6

You cannot use selectsinglenode to retrieve elements. In this way, RSS cannot change the order, and the atom format cannot be processed well!

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.