Hi Mariano. Some like this: xmlWriter := XMLWriter new writeWith: [ :writer | writer enablePrettyPrinting; xml; comment: 'Generated from Pharo.'. writer tag: 'root' with: [ writer tag: 'parent1' with: [ writer tag: 'child1' with: 'grrr'. writer tag: 'child2' with: 'grrr' ]. writer tag: 'parent2' with: [ writer tag: 'child3' with: 'buhhhr' ] ] ]. xml := xmlWriter contents. 2013/2/27 Mariano Martinez Peck <marianopeck@gmail.com>
Hi guys. I am using XMLWriter from http://www.squeaksource.com/XMLWriterto write a specific XML that a protocol expects. What I need is to build the XML file from parent to children and dynamically. For example, I want to be able to define a tag, but then, later on, add more tags to a parent element. I found this impossible to do with the current XMLWriter. Here, messages like #tag:with: , #with: do not help. I know I will need to build everything in memory and send a "write contents" at the end to get the final XML string...
For example, say I wanna build this XML:
<root> <parent1> <child1>grrr<child1> <child2>grrr<child2> </parent1> <parent2> <child3>buhhh<child3> </parent2> </root>
i would like an API like this:
| xmlWriter | xmlWriter := XMLWriter new. xmlWriter tag: 'root'. (xmlWriter named: 'root') tag: 'parent1'. (xmlWriter named: 'parent1') tag: 'child' with: 'grrr'. (xmlWriter named: 'root') tag: 'parent2'. .... xmlWriter write contents.
Or even if I don't have #named: but I can store them in instVars it would be fine:
| xmlWriter rootTag parent1Tag | xmlWriter := XMLWriter new. rootTag xmlWriter tag: 'root'. parent1Tag rootTag tag: 'parent1'. parent1Tag tag: 'child' with: 'grrr'. rootTag tag: 'parent2' xmlWriter write contents.
Any ideas how to do this?
Thanks,
-- Mariano http://marianopeck.wordpress.com