Jump to content

Sample XML


nobbe
 Share

Recommended Posts

maybe someone may find it useful :D

; ----------------------------------------------------------------------------
; sample how to retrieve XML information from a "non numbered list" when all items are "the same name"
;
; http://feeds2.feedburner.com/wettercom/rss

#cs sample like

    <item>
    <title>Österreichwetter</title>
    <description>Heute ...</description>
    </item>
    
    <item>
    <title>Schweizwetter</title>
    <description>Der Tag ...</description>
    </item>
    
author nobbe    04.2009
    
#ce

; ----------------------------------------------------------------------------
#include <inet.au3>
#include <array.au3>

; important for loading 
#include <_XMLDomWrapper.au3>

$load_directy=0

if $load_directy > 0 then 

    ; load directly
    $strXML= _INetGetSource("http://feeds2.feedburner.com/wettercom/rss")
    _XMLLoadXML($strXML, "")

else ; save into TEMP fiel first to check the XML data by hand 

    InetGet("http://feeds2.feedburner.com/wettercom/rss", @ScriptDir & "\weather.xml", 1, 0)
    $FileOpen = _XMLFileOpen(@ScriptDir & "\weather.xml")
endif 

    ; single item

    ;$node = "//rss/channel/item/description";
    ;$node = "//channel/item/description";
    ;$node = "//item/description";

    $title_node = "//rss/channel/item/title";
    $title_single = _GetFirstValue($title_node)

    If $title_single <> -1 Then
        MsgBox(0, "Title Single", $title_single)
    EndIf

    ;; multiple entries 

    $title_node = "//rss/channel/item/title";
    $title_array = _XMLGetValue($title_node)

    $descr_node = "//rss/channel/item/description";
    $descr_array = _XMLGetValue($descr_node)

    ; all array values : [0] holds number 
    For $i = 1 To $title_array[0]
        MsgBox(0, "Value " & $i, $title_array[$i] & @CRLF & @CRLF & $descr_array[$i])
    Next

exit ; 


; retruns array---
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        
        _ArrayDisplay($ret_val, '_XMLGetValue  ' & $node)
        
        Return ($ret_val[1])
    Else
        Return SetError(1, 3, 0)
    EndIf
EndFunc   ;==>_GetFirstValue
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...