xml := BtbXmlRenderer on: writeStream.
xml render: #(first arg1: 'value1' arg2: 'value2'
(second (third '"fun"'))
(fourth)
(fifth #sixth: 56)).
And this generates the following XML:
<?xml version="1.0"?>
<first arg1="value1" arg2="value2">
<second>
<third>"fun"</third>
</second>
<fourth/>
<fifth sixth="56"/>
</first>
I made all objects implement #renderXMLOn: so that I can use Arrays, Blocks, or anything else to make it easier to output XML in the future. It also means I can use all three approaches to generate one XML document. I think this is a perfect example of polymorphism and the power of dynamic languages at its finest. So, we have three ways of generating XML and I found that each has its advantages at different times. My point to this post was to show yet another way to generate XML using Smalltalk. Keep the Smalltalk flowing!
No comments:
Post a Comment