Parsing Tags
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
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;)
Cheers
LL
/*
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;
setoutletassist(1,"values");
setoutletassist(0,"index");
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
if (i%2){ //since all the values will have a odd-valued index, we can do a test
outlet(0,index);
outlet(1,splitList[i]);
index = index + 1;
}//end IF
}// end FOR
} // end function
function bang()
{
weatherReport(someText);
}
Absolutely brilliant, works really well, thanks