Try this approach, since this is an XML-like format that you need to unwind to database style.

every line begins with word 1 as a category
 then a string of attributes as
     attrib="string with spaces"

--------- working code ---------------
on parseToArray
   put fld 1 into block --your data
   set the itemDel to "="
   repeat for each line LNN in block

      put word 1 of LNN into cat
      put word 2 to -1 of LNN into attributes
      replace (quote&space) with (quote&cr) in attributes
      --because it is like XML, we need to...
      if cat = "forecast" then
         get line 1 of attributes
         put char 2 to -2 of item 2 of IT after cat
         --making cat unique for an array
         delete line 1 of attributes
      end if
      -- now every pair is on a separate line
      --build an array of unique keys using 'cat'
      repeat for each line ATR in attributes
put char 2 to -2 of item 2 of ATR into arrayStor[ (cat && word 1 of item 1 of ATR) ]
      end repeat
   end repeat

   combine arrayStor using cr and "^"
   ;put arrayStor
end parseToArray

------------------------- output
astronomy sunrise^7:39 am
astronomy sunset^4:58 pm
atmosphere humidity^51
atmosphere pressure^30.04
atmosphere rising^1
atmosphere visibility^10
condition code^26
condition date^Tue, 28 Dec 2010 4:52 pm EST
condition temp^30
condition text^Cloudy
forecastTue code^27
forecastTue date^28 Dec 2010
forecastTue high^30
forecastTue low^22
forecastTue text^Mostly Cloudy
forecastWed code^28
forecastWed date^29 Dec 2010
forecastWed high^32
forecastWed low^25
forecastWed text^Mostly Cloudy
location city^Bethel Park
location country^United States
location region^PA
units distance^mi
units pressure^in
units speed^mph
units temperature^F
wind chill^21
wind direction^250
wind speed^10


On Dec 28, 2010, at 2:58 PM, Thomas McGrath III wrote:

I am stuck. I've been trying to extract text from an RSS feed and so far I have the information I need but am stuck at extracting it into a better format. Here is what I have so far:

location city="Bethel Park" region="PA"   country="United States"
units temperature="F" distance="mi" pressure="in" speed="mph"
wind chill="21"   direction="250"   speed="10"
atmosphere humidity="51" visibility="10" pressure="30.04" rising="1"
astronomy sunrise="7:39 am"   sunset="4:58 pm"
condition text="Cloudy" code="26" temp="30" date="Tue, 28 Dec 2010 4:52 pm EST" forecast day="Tue" date="28 Dec 2010" low="22" high="30" text="Mostly Cloudy" code="27" forecast day="Wed" date="29 Dec 2010" low="25" high="32" text="Mostly Cloudy" code="28"

I can't delimit with space as "location city" has a space in it.
I can't use = because then I get " "Bethel Park" region" instead of just "Bethel Park"

Jim Ault
Las Vegas



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to