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

[REBOL] Re: XML-Maker Function!

From: mike::yaunish::home::com at: 13-Feb-2001 11:51

There is one small change that needs to be made to this function. If you do the following the problem becomes obvious. a: xml-maker [ 'red 1.21.3 ] == [<red> 1.21.3 </red>]
>> a: xml-maker [ 'red 1.21.3 ]
== [<red> 1.21.3 </red> <red> 1.21.3 </red>]
>> a: xml-maker [ 'red 1.21.3 ]
== [<red> 1.21.3 </red> <red> 1.21.3 </red> <red> 1.21.3 </red>] The ouput-block initialization should read: output-block: copy []
>Modified (for proper closing tag) xml-maker function from Mark: > >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 > end-tag: to-tag join "/" pick block 1 > block: next block > value: pick block 1 > block: next block > append output-block reduce [tag value end-tag] > ] > return output-block >] > >--Scott > >> >From: "Deryk Robosson" > > Mark wrote: > > > > > > 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" > > > > Where are the closing tags? This would never pass a validation. :) > > > > Deryk > > > > > subject, without the quotes. > > > >-- >To unsubscribe from this list, please send an email to >[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
Mike Yaunish [mike--yaunish--home--com]