Quantcast
Channel: robsmart.co.uk » virtualworlds
Viewing all articles
Browse latest Browse all 10

XML Parsing in OpenSim: Example – reading RSS feeds

$
0
0

In OpenSim you’re not just restricted to using LSL for scripting, it’s also possible to use c#. This opens up the possiblilities for far more powerful scripts that can access c# in built libraries.

For example I’ve previously mentioned that the string processing methods in Second Life are not very flexible when it comes to reading formatted data. Thus the reason I implemented the osParseJSON method to make Web APIs easier to use.

Obviously another common data format is XML, in this case I don’t have to implement any new OpenSim script functions because the XML capabilities are available natively in c#.

Here is a simple example of reading the RSS feed for my blog, and reading out the entries in chat.


//c#
// displays the contents of an RSS 2.0 feed

string URL = “http://robsmart.co.uk/feed”;
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
LSL_Types.LSLString requestID;

public void default_event_state_entry()
{
llSay(0,”RSS reader current Feed is ” + URL);
getFeedContent();

}

public void getFeedContent()
{
requestID = llHTTPRequest(URL, new LSL_Types.list(), “” );
}

public void default_event_touch_start(LSL_Types.LSLInteger total_number)
{
// read out the RSS feed.
displayFeed();

}

public void displayFeed()
{
System.Xml.XmlNodeList items = xDoc.GetElementsByTagName(“item”);

for(int i=0;i < items.Count ; i++)
{
string title = items[i].SelectSingleNode(“title”).InnerXml;
string link = items[i].SelectSingleNode(“link”).InnerXml;

string description=”no description available”;

if(items[i].SelectSingleNode(“description”)!=null)
description = items[i].SelectSingleNode(“description”).InnerXml;

llSay(0,title + “\n” + description + “\n”);
}
}

public void default_event_http_response(LSL_Types.LSLString request_id, LSL_Types.LSLInteger status, LSL_Types.list metadata, LSL_Types.LSLString body)
{
if (requestID == request_id)
{
// store the xml
xDoc.LoadXml(body);

// process the xml
llOwnerSay(“loaded feed”);
}
}


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images