robsmart.co.uk

Emerging technology, Open Source and the Internet
  • rss
  • Home
  • About
  • Press

XML Parsing in OpenSim: Example – reading RSS feeds

Rob Smart | October 27, 2008

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”);
}
}

Categories
Tags
c#, opensim, scripting, secondlife, virtualworlds
Comments rss
Comments rss
Trackback
Trackback

« Thoughts on OpenSim, interview on UgoTrade Visualizing live shipping data in OpenSim (Isle of Wight Ferries) »

6 Responses to “XML Parsing in OpenSim: Example – reading RSS feeds”

  1. Larry says:
    February 13, 2009 at 10:00 pm

    Sorry, I am using version 0.62 and have enabled c# compiling. I pasted your script to the script window, but when it compiles it says that System doesn’t contain Xml (The type or namespace name ‘Xml’ does not exist in the namespace ‘System’ (are you missing an assembly reference?))

    Other namespaces in System seem to be ok, but I can’t get Xml working, and it is very useful!

    Where can I find the syntax to use in such scripts? For example namespace and using statements are not accepted either.

    Thanks in advance!

  2. Rob says:
    February 13, 2009 at 11:40 pm

    Hi Larry,

    Are you using the pre-built 0.62 version for windows or linux ?

    I just tried the script again on the latest version straight from SVN and it worked fine. If you like you can email me your OpenSim.ini file and i’ll see if there is something in your settings that prevents this from working.

    my email is rob.s.smart AT gmail.com

  3. Mike says:
    April 24, 2009 at 1:46 pm

    Is OpenSim Generally reasonably straightforward to use – my boss has just asked me about it and I’m trying not to look like a nodding dog. Have just been to opensimulator.org to download a copy – hopefully I’ll get the hang of it quickly as he wants some investigations for tuesday

  4. su says:
    September 12, 2009 at 3:39 am

    Hi Rob,
    I am also getting the same error that Larry got. were you being able to figure out the cause for that?
    Or is it ok for me to e-mail you my opensim.ini file?
    I am using 0.6.6 (I just downloaded the setup.exe, did not build it from the source code)

    Su

  5. su says:
    September 13, 2009 at 4:33 am

    http://opensimulator.org/mantis/view.php?id=4137
    Seems like references are harcoded in the compiler. Is there a way to change that?

  6. Dimitha says:
    November 12, 2009 at 9:10 am

    Hello everyone,

    I am also getting the the same error that Larry got (System doesn’t contain Xml (The type or namespace name ‘Xml’ does not exist in the namespace ‘System’ (are you missing an assembly reference?)).

    I am using 0.6.7. Any idea??

    Regards,
    Dimitha

Leave a Reply

Click here to cancel reply.

Tags

3d aberdeen anime api arabic art avatar c# drawing environment ets ets hursley ibm press flickr google hursley ibm ibm hursley ets rockets filming photography image processing jeddah lsl machinima openid opensim pervasive photography press saudi scripting secondlife security simile sony home streaming timeline transliteration twister video virtualworlds virtualworlds secondlife ibm linden wacom wacom concept art deviantart graphics wave power weather web 2.0 webmaster

  • Andy Piper
  • Dale Lane
  • Darren Shaw
  • Eightbar
  • Feeding Edge
  • Gareth Jones
  • Hannah Parker
  • Ian Hughes
  • Ian Smith
  • Irving Wladawsky-Berger
  • James Taylor
  • John Tolva
  • Kelly Drahzal
  • Martin Gale
  • Michael Rowe
  • Michael Rowe
  • Mo Hax
  • Nick O’Leary
  • Penny Glazzard – Zzing marketing
  • Pranab Sharma
  • Rita J. King
  • Roo Reynolds
  • Rosemary Gardening

  • Photography

Twitter feed

  • No public Twitter messages.

Recent Comments

  • Jarvan on Transliteration again … now complete
  • Kristin on Transliteration again … now complete
  • » Favorite links of 2007 Ascent Stage on Your Flickr timeline with Simile
  • pat on Transliteration again … now complete
  • Jack on Home VOIP system using FreeSwitch and a Linksys 3102 voice gateway (UK Guide)
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox