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

XML-Maker Function!

 [1/5] 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!]] [
<<quoted lines omitted: 65>>
>[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
Mike Yaunish [mike--yaunish--home--com]

 [2/5] 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

 [3/5] from: deryk:iitowns at: 12-Feb-2001 20:32


[Robbo1Mark--aol--com] wrote:
> ANDREW, > here's a quickly knocked up function to make XML from a block of REBOL values.
<<quoted lines omitted: 15>>
> ** 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

 [4/5] from: gjones05:mail:orion at: 12-Feb-2001 6:54


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

 [5/5] from: robbo1mark:aol at: 12-Feb-2001 8:23


SCOTT, thanks for fixing this oversight on my behalf, an example of the list in action "at it's best" cheers again, Mark Dickson

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted