Yes I suspected that this was what you wanted to say. Regards. 2013/2/27 Mariano Martinez Peck <[email protected]>
> > > On Wed, Feb 27, 2013 at 4:24 PM, Gastón Dall' Oglio < > [email protected]> wrote: > >> 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. >> >> > Thanks Gaston. But that exactly what I cannot do ;) Looks like I didn't > express myself well. > In this case, you are defining a tag completely from the beginning. For > example, to write parent1 and parent2 you already have to pass them from > the beginning to the root. > I want to be able to do that at different times. Add one, THEN (not in the > same block closure) the other one. > > Please let me know if my problem is clear. Otherwise, I try again :) > > >> >> >> >> 2013/2/27 Mariano Martinez Peck <[email protected]> >> >>> 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 >>> >> >> > > > -- > Mariano > http://marianopeck.wordpress.com >
