Still more fun with XML [message #43231] |
Thu, 24 March 2005 08:44 |
Karl Schultz
Messages: 341 Registered: October 1999
|
Senior Member |
|
|
Since we're so deep into XML...
There's a really fun undocumented feature (that will be documented in the
next IDL) that allows the IDL XML DOM parser to read XML from a URL
instead of a local file.
Note the value of the FILENAME kwd in the code below.
This program reads an RSS feed from this weather web site. In particular,
it gets the weather for the Fort Collins - Loveland airport in Colorado.
Of course, you can change it to whatever airport you wish, as long as it
is reported on this site.
There is no DTD, but the RSS specifications are readily available and I
used those as a guide for this parser. I actually have a full RSS parser
in the works, but I need to finish it up.
Have fun,
Karl
++++++
pro weather
oDoc = OBJ_NEW('IDLffXMLDOMDocument', $
FILENAME='http://weather.gov/data/current_obs/KFNL.rss')
;; Get and print first title
oTitles = oDoc->GetElementsByTagName('title')
oTitle = oTitles->item(0)
oTextNodes = oTitle->getChildNodes()
print, (oTextNodes->item(0))->getNodeValue()
OBJ_DESTROY, oTitles
;; Loop through all the items, printing the titles and descriptions.
oItems = oDoc->GetElementsByTagName('item')
for i=0, oItems->getLength()-1 do begin
oItem = oItems->item(i)
oTitle = (oItem->GetElementsByTagName('title'))->item(0)
oTextNodes = oTitle->GetChildNodes()
for j=0, oTextNodes->getLength()-1 do $
print, (oTextNodes->item(j))->getNodeValue()
OBJ_DESTROY, oTitle
oDesc = (oItem->GetElementsByTagName('description'))->item(0)
oTextNodes = oDesc->GetChildNodes()
for j=0, oTextNodes->getLength()-1 do $
print, (oTextNodes->item(j))->getNodeValue()
OBJ_DESTROY, oDesc
endfor
print
OBJ_DESTROY, oDoc
end
|
|
|