Tango XML - Querying the weather in London
March 7, 2008 on 2:44 am | In Uncategorized |Scott Sanders wrote an interesting post today on
Here’s a quick excerpt
I was helping someone on IRC in #d.tango try to use tango.text.xml to parse and display data from an xml document. We ended up building a simple example using HttpGet to get the document, Document to parse it, and Document’s xpath-like querying functionality to extract the useful bits.
import tango.io.File;
import tango.io.Stdout;
import tango.text.xml.Document;
import tango.net.http.HttpGet;
void main ()
{ /> auto doc = new Document!(char); /> auto page = new HttpGet (”http://www.google.com/ig/api?weather=London”); /> auto content = cast (char[]) page.read; doc.parse (content); foreach( node; doc.query.descendant[”forecast_conditions”]) { Stdout.formatln(”forecast for {} is {} with a high of {}”, node.query[”day_of_week”].attribute.nodes[0].value, node.query[”condition”].nodes[0].getAttribute(”data”).value, node.query[”high”].nodes[0].getAttribute(”data”).value); }
}
The D programming language coupled with Tango as a standard library allows you to become a productive programmer.
Source
Read the rest of this great post here
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
You must be logged in to post a comment.
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^