[Pharo-project] XMLWriter question

Gary Chambers gazzaguru2 at btinternet.com
Wed Feb 23 14:33:00 CET 2011


Not sure what the current XMLParser api is like but this is a snippet of 
what we used in Squeak for ReportBuilder...


toXMLWriter: aWriter
 "Populate the writer from the receiver."

 |e pt |
 e := super toXMLWriter: aWriter.
 self @ #repeat ifNotNilDo: [:b | e attributeAt: #repeat put: (b ifTrue: 
['repeat'] ifFalse: ['no-repeat'])].
 self @ #direction ifNotNilDo: [:s | e attributeAt: #direction put: (s = 
#leftToRight ifTrue: ['lr'] ifFalse: ['tb'])].
 pt := XMLElement named: 'printThings'.
 e addElement: pt.
 self items do: [:i |
  aWriter element: pt.
  i toXMLWriter: aWriter].
 ^e

Regards, Gary

----- Original Message ----- 
From: "Stéphane Ducasse" <stephane.ducasse at inria.fr>
To: "pharo Development" <Pharo-project at lists.gforge.inria.fr>
Cc: "Moose-related development" <moose-dev at iam.unibe.ch>
Sent: Monday, February 21, 2011 8:58 AM
Subject: [Pharo-project] XMLWriter question


Hi guys

I have a question about XMLWriter. I have cards and group of cards.
Each class know how to serialize itself.

For card I have xmlOn: (one of my methods) that describes the card 
attributes

Card>>xmlOn: aWriter
"write a description of the receiver properties as xml uing aWriter, an 
instance of XMLWriter"

aWriter tag
name: #card;
with: [self xmlInstVarOn: aWriter]


Group>>xmlOn: aWriter
"write a description of the receiver properties as xml uing aWriter, an 
instance of XMLWriter"

| cardWriter |
cardWriter := XMLWriter new.
cards do: [:each | each xmlOn: cardWriter].

aWriter tag
name: #group;
with: [
aWriter tag: #groupName with: self groupName.
aWriter tag: #cards with: [ aWriter raw:  cardWriter contents]]


And I'm not really happy. Because I would like to avoid to use raw: and 
instantiate a new writer.

I would like to know how I could use the write to pass the results of the 
iteration over cards
I wanted to write something like

aWriter tag
name: #group;
with: [
aWriter tag: #groupName with: self groupName.
aWriter tag: #cards with: [self cards do: [:each | each xmlOn: aWriter]]












More information about the Pharo-project mailing list