How can I control that each of the node of my document get printed a cr at its end?
In the past I got that <?xml version="1.0" encoding="UTF-8" ?> <BDBase date="25 May 2010" entriesNumber="2440" note="nil"> <bd authors="Larcenet" editor="Dargaud" entryCreationDate="25 March 2006" entryNumber="1" number="1" original="true" serie="Nic oumouk" serieComplete="false" title="Total souk pour nic oumouk" year="2005"/> <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="2" notes="sur le 4eme de couv aventure a manhattan" number="9" original="true" serie="Achille Talon" title="Les petits desseins d'Achille Talon" year="1974"/> <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="3" notes="sur la couverture une histoire du journal tintin" number="13" original="true" serie="Achille Talon" title="Pas de pitié pour Achille Talon" year="1976"/> <bd aut Now I get <?xml version="1.0" encoding="UTF-8"?><Base date="31 October 2010" entriesNumber="2448" note="nil"><bd serieComplete="false" editor="Dargaud" entryCreationDate="25 March 2006" entryNumber="1" authors="Larcenet" title="Total souk pour nic oumouk" serie="Nic oumouk" original="true" number="1" year="2005" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="2" authors="Greg" title="Les petits desseins d'Achille Talon" serie="Achille Talon" original="true" notes="sur le 4eme de couv aventure a manhattan" number="9" year="1974" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="3" authors="Greg" title="Pas de pitié pour Achille Talon" serie="Achille Talon" original="true" notes="sur la couverture une histoire du journal tintin" number="13" year="1976" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="4" authors="Greg" title Thanks Stef |
In my really old code I wrote save "self new save" | doc | doc := self buildXML. doc printOn: self stream buildXML ^ self base asXML Base>>asXML "BDBase uniqueInstance asXML" | doc elem | doc := XMLDocument new. doc version: '1.0'. elem := XMLElement name: #Base attributes: (Dictionary new at: 'date' put: Date today asString; at: 'entriesNumber' put: self elements size asString; at: 'note' put: self note asString; yourself). doc addElement: elem. self elements do: [:each | elem addElement: each asXML]. ^ doc Elements>>asXML ^ XMLElement name: self class xmlName attributes: self attributes So how can I control that each elements ends with a linebreak/cr whatever? Stef |
In reply to this post by stephane ducasse
Patching XMLNode>>printOn: like that seems to work.
XMLNode>>printOn: aStream | writer | writer := XMLWriter on: aStream. >> writer enablePrettyPrinting. self printXMLOn: writer. writer flushMarkup. Now this is clearly not a good solution. I will change my code not to be based on the printOn behavior and use a writer instead. Now I do not understand why we create a writer for each printOn: message Stef On Oct 31, 2010, at 12:03 PM, Stéphane Ducasse wrote: > > In my really old code I wrote > > save > "self new save" > > | doc | > doc := self buildXML. > doc printOn: self stream > > > buildXML > > ^ self base asXML > > > Base>>asXML > "BDBase uniqueInstance asXML" > > | doc elem | > doc := XMLDocument new. > doc version: '1.0'. > elem := XMLElement > name: #Base > attributes: > (Dictionary new > at: 'date' put: Date today asString; > at: 'entriesNumber' put: self elements size asString; > at: 'note' put: self note asString; > yourself). > doc addElement: elem. > self elements do: [:each | elem addElement: each asXML]. > ^ doc > > Elements>>asXML > ^ XMLElement name: self class xmlName attributes: self attributes > > > So how can I control that each elements ends with a linebreak/cr whatever? > > Stef > > > > > |
In reply to this post by stephane ducasse
You can use printCanonicalOn: and subclass XMLWriter.
Unfortunatly, there is no test about it. David, it would be good to add some... Cheers, Alexandre On 31 Oct 2010, at 07:56, stephane ducasse wrote: > How can I control that each of the node of my document get printed a cr at its end? > > In the past I got that > > <?xml version="1.0" encoding="UTF-8" ?> > <BDBase date="25 May 2010" entriesNumber="2440" note="nil"> > <bd authors="Larcenet" editor="Dargaud" entryCreationDate="25 March 2006" entryNumber="1" number="1" original="true" serie="Nic oumouk" serieComplete="false" title="Total souk pour nic oumouk" year="2005"/> > <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="2" notes="sur le 4eme de couv aventure a manhattan" number="9" original="true" serie="Achille Talon" title="Les petits desseins d'Achille Talon" year="1974"/> > <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="3" notes="sur la couverture une histoire du journal tintin" number="13" original="true" serie="Achille Talon" title="Pas de pitié pour Achille Talon" year="1976"/> > <bd aut > > Now I get > > <?xml version="1.0" encoding="UTF-8"?><Base date="31 October 2010" entriesNumber="2448" note="nil"><bd serieComplete="false" editor="Dargaud" entryCreationDate="25 March 2006" entryNumber="1" authors="Larcenet" title="Total souk pour nic oumouk" serie="Nic oumouk" original="true" number="1" year="2005" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="2" authors="Greg" title="Les petits desseins d'Achille Talon" serie="Achille Talon" original="true" notes="sur le 4eme de couv aventure a manhattan" number="9" year="1974" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="3" authors="Greg" title="Pas de pitié pour Achille Talon" serie="Achille Talon" original="true" notes="sur la couverture une histoire du journal tintin" number="13" year="1976" /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="4" authors="Greg" title > > Thanks > > Stef -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. |
In reply to this post by Stéphane Ducasse
Strange indeed, we will check
Cheers, Alexandre On 31 Oct 2010, at 08:13, Stéphane Ducasse wrote: > Patching XMLNode>>printOn: like that seems to work. > > > XMLNode>>printOn: aStream > | writer | > > writer := XMLWriter on: aStream. >>> writer enablePrettyPrinting. > self printXMLOn: writer. > writer flushMarkup. > > Now this is clearly not a good solution. I will change my code not to be based on the printOn behavior and use a > writer instead. > > Now I do not understand why we create a writer for each printOn: message > > > Stef > > > > > On Oct 31, 2010, at 12:03 PM, Stéphane Ducasse wrote: > >> >> In my really old code I wrote >> >> save >> "self new save" >> >> | doc | >> doc := self buildXML. >> doc printOn: self stream >> >> >> buildXML >> >> ^ self base asXML >> >> >> Base>>asXML >> "BDBase uniqueInstance asXML" >> >> | doc elem | >> doc := XMLDocument new. >> doc version: '1.0'. >> elem := XMLElement >> name: #Base >> attributes: >> (Dictionary new >> at: 'date' put: Date today asString; >> at: 'entriesNumber' put: self elements size asString; >> at: 'note' put: self note asString; >> yourself). >> doc addElement: elem. >> self elements do: [:each | elem addElement: each asXML]. >> ^ doc >> >> Elements>>asXML >> ^ XMLElement name: self class xmlName attributes: self attributes >> >> >> So how can I control that each elements ends with a linebreak/cr whatever? >> >> Stef >> >> >> >> >> > > -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. |
Free forum by Nabble | Edit this page |