Forums > Javascript

Parsing Tags

May 07 2009 | 5:33 am

Hi all,
I’m grabbing some weather into Max and one of the lines that the RSS/XML stream returns is –

text="Mostly Cloudy" code="28" temp="9" date="Thu, 7 May 2009 5:50 am BST"

Is there anyway i can grab the values of each element? (ie: grabbing the data between the quotes whilst keeping the formating)

I know under HTML Javascript you have access to the ‘getElementsByTagName’ which can do something similar, but i can’t for the life of me able to work out a way to do it in JS under Max.

Cheers Smile

May 07 2009 | 9:29 am

You could split the text up based on the quotation marks. But quotation marks are a bit tricky. In my script I’ve escaped them, before they are splitted into an array. Then all the odd-valued indexes ar sent out the right outlet.

This is not a very good solution, but since I was doing something similar myself, I had to have a go;)


Takes a string and sends the values between the quotation marks out it’s right outlet, along with indexes on it the left outlet
// set up inlets/outlets/assist strings
outlets = 2;

var someText = "text="Mostly Cloudy" code="28" temp="9" date="Thu, 7 May 2009 5:50 am BST"" //the quotation marks needs to be escaped, so this isn’t really a clever way to do this
var splitList = new Array()

function weatherReport(report){
var index = 0;

var splitList = report.split(/x22/g); //this splits the text using a regex with a modifier set to "global"
for(i=0;i< (splitList.length-1);i++) {
if (i%2){ //since all the values will have a odd-valued index, we can do a test
index = index + 1;
}//end IF
}// end FOR
} // end function

function bang()

May 07 2009 | 12:09 pm

Absolutely brilliant, works really well, thanks Smile

Viewing 3 posts - 1 through 3 (of 3 total)

Forums > Javascript