Jump to content

Unable To Walk Xml Tree


Recommended Posts

I'd like to try my hand at making an rss reader (as a noob), but I'm unable to walk the xml tree in a rdf file, using the examples shown here already. So, after two days of trying, I'd figured I'd ask. Below I have a sample rss feed, that I like to parse into a two pane window (feed leafs on left with headlines, and article on right).

Here's a sample feed.

Thanks in Advance

=====START=====

<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0">

<channel>

<title>mysite.com</title>

<link>http://www.mysite.com/rssclick/?section=cnn_topstories</link>

<description>mysite.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.</description>

<language>en-us</language>

<copyright>© 2006 musite.com.</copyright>

<pubDate>Mon, 03 Apr 2006 19:54:53 EDT</pubDate>

<ttl>5</ttl>

<image>

<title>xxx.com</title>

<link>http://www.mysite.com/rssclick/?section=cnn_topstories</link>

<url>http://i.cnn.net/cnn/.element/img/1.0/logo/cnn.logo.rss.gif</url>

<width>144</width>

<height>33</height>

<description>mysite.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.</description>

</image>

<item>

<title>Moussaoui: God curse you all</title>

<link>http://www.mysite.com/rssclick/2006/LAW/04/03/moussaoui.verdict/index.html?section=cnn_topstories</link>

<description>Al Qaeda conspirator Zacarias Moussaoui is eligible for the death penalty, a federal jury decided Monday in the first U.S. trial about the September 11, 2001, attacks. Jurors agreed with prosecutors that his lies to FBI agents resulted in 9/11 deaths. After jurors left the courtroom, Moussaoui shouted, "You'll never get my blood. God curse you all."</description>

<pubDate>Mon, 03 Apr 2006 18:40:38 EDT</pubDate>

</item>

<item>

<title>Replacement organs grown from patients' own cells</title>

<link>http://www.mysite.com/rssclick/2006/HEALTH/conditions/04/03/engineered.organs/index.html?section=cnn_topstories</link>

<description>Kaitlyne McNamara no longer worries about feeling different at school.</description>

<pubDate>Mon, 03 Apr 2006 18:32:04 EDT</pubDate>

</item>

</channel>

</rss>

======END=========

Link to comment
Share on other sites

Please use the correct forum for support questions.

PS:

Look at the ExelCOM UDF somewhere in Scripts & Scraps

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Moderators

I need a good one, I just whipped this up, neogia has got me trying my hand at StringRegExp() (I still suck at it). Anyway, you'll need Beta (can be downloaded from the sticky in the Developers forum)

#include <guiconstants.au3>

Local $RSSFEED_TXT_LOCATION = @DesktopDir & "\RSS_FEED.xml"

$MAIN_GUI = GUICreate('RSS FEED', 600, 420)
$HEADER = GUICtrlCreateEdit('', 10, 10, 280, 330)
$DESCRIPTION = GUICtrlCreateEdit('', 310, 10, 280, 330)
GUICtrlCreateLabel('URL: http://', 40, 348, 60, 20)
$URL_INPUT = GUICtrlCreateInput('', 105, 345, 450, 20)
$RETRIEVE_BUTTON = GUICtrlCreateButton('Retrieve Info', 260, 375, 80, 30)
GUISetState()

While 1
    $MAINMSG = GUIGetMsg()
    Select
        Case $MAINMSG = $GUI_EVENT_CLOSE
            Exit
        Case $MAINMSG = $RETRIEVE_BUTTON
            If GUICtrlRead($URL_INPUT) <> '' And Not StringInStr(GUICtrlRead($URL_INPUT), 'http:/') Then
                DOWNLOADRSSFEED('http://' & GUICtrlRead($URL_INPUT), $RSSFEED_TXT_LOCATION)
            Else
                MsgBox(64, 'Error', 'You need to put a web address to the RSS Feed in.')
            EndIf
    EndSelect
WEnd

Func RSS_FEED($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If @error == 0 Then Return $a_Array
EndFunc

Func DOWNLOADRSSFEED($s_URL, $h_DOWNLOADFILE)
    If FileExists($h_DOWNLOADFILE) Then
        Do
            FileDelete($h_DOWNLOADFILE)
            Sleep(10)
        Until Not FileExists($h_DOWNLOADFILE)
    EndIf
    If InetGet($s_URL, $h_DOWNLOADFILE) = 0 Then
        SetError(1)
        Return 0
    EndIf
    Do
        Sleep(10)
    Until FileExists($h_DOWNLOADFILE)
    ConsoleWrite(4 & @LF)
    Local $s_TITLE_TXT = RSS_FEED($h_DOWNLOADFILE, '<title>', '</title>')
    Local $s_DESCRIPTION_TXT = RSS_FEED($h_DOWNLOADFILE, '<description>', '</description>')
    Local $STOREHEAD = '', $STOREDESCRIPTION = ''
    For $i = 1 To UBound($s_TITLE_TXT) - 1
        $STOREHEAD &= $s_TITLE_TXT[$i] & @CRLF
    Next
    For $x = 1 To UBound($s_DESCRIPTION_TXT) - 1
        $STOREDESCRIPTION &= $s_DESCRIPTION_TXT[$x] & @CRLF
    Next
    GUICtrlSetData($HEADER, $STOREHEAD)
    GUICtrlSetData($DESCRIPTION, $STOREDESCRIPTION)
EndFunc
This should at least get you started (did me :)).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...