Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] XML-Maker Function!

From: robbo1mark:aol at: 12-Feb-2001 6:54

ANDREW, here's a quickly knocked up function to make XML from a block of REBOL values. Note the value block should contain 'tag 'value 'tag2 'value2 etc etc. anyway here's the func. xml-maker: func [ block [block!]] [ if not even? (length? block) [ make error! "Imbalance Between Tags & Values"] block: reduce block output-block: [] count: (length? block) / 2 loop count [ tag: to-tag pick block 1 block: next block value: pick block 1 block: next block append output-block reduce [tag value tag] ] return output-block ]
>> xml-maker [ 'red 255.0.0 'green 0.255.0 'blue 0.0.255 ]
== [<red> 255.0.0 <red> <green> 0.255.0 <green> <blue> 0.0.255 <blue>]
>> xml-maker [ 'red 255.0.0 'green 0.255.0 'blue ]
** User Error: Imbalance Between Tags & Values. ** Where: make error! "Imbalance Between Tags & Values"
>>
cheers Andrew, Mark Dickson