Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HTTP Help

Smithy Zeno
ownes 9 pet cacti
Join date: 3 Aug 2006
Posts: 52
02-02-2008 17:15
Hey all,
I've been tinkering with llHTTPRequest to get data from webpages. Basically, I want to take this....

CODE

[17:10] Object: <?xml version="1.0" encoding="UTF-8"?><city>
<host>reggiano.myminicity.com</host>
<name>Reggiano</name>
<region code="US">united states</region>
<ranking>30183</ranking>
<population>7</population>
<incomes>1050</incomes>
<unemployment>0</unemployment>
<transport>100</transport>
<criminality>0</criminality>
<pollution>0</pollution>
<nextnuke>1</nextnuke>
<signatures>0</signatures>
<bases com="0" env="0" ind="0" sec="0" tra="0"/>
</city>

....and separate all of the information and display it with hover text. I could use llGetSubString, but that is very inaccurate. If someone could tell me how to separate this information and display it, that'd be great. Thanks for any help in advance.
_____________________
-Smithy
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
02-02-2008 18:22
You have to use "llParseString2List" function, this function will convert your string into a list with the separators that you choose, this is the header of the function:

list llParseString2List(string src, list separators, list spacers)

it returns a list and inside you have to put the string and a list of separators.

In this case you can use as separators

</host>
</name>
</region>

etc.

for example:

newList = llParseString2List(data,["</host>","</name>","</regions>"],[]);

For more information about how to use this function....always:

http://lslwiki.net/lslwiki/wakka.php?wakka=llParseString2List
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-02-2008 19:29
Unfortunately LSL is NOT setup very well for parsing XML, to say the least. If you have really, really simple XML (no entities, no DTD, etc.) such as that given in the original post, you can probably get away with a very simple SAX-type parser (http://www.saxproject.org/) that looks for the next less-than symbol ('<').

I would recommend against using the 'llParseString...' functions for this, actually, as they are likely to take up a lot of memory even for small documents. I suspect you'd be better off breaking off the portion of the string already processed and then using llGetSubStringIndex() or even scanning character by character for some tasks (e.g. determining whether a greater-than symbol is within an attribute value or actually ends a tag).

For anything but the most simplistic documents, I'd recommend implementing a full parser on your own external server that can parse and re-package the data into a form that is more useful to your script and application.
Smithy Zeno
ownes 9 pet cacti
Join date: 3 Aug 2006
Posts: 52
02-03-2008 11:05
Thanks for all the help!!!
_____________________
-Smithy