That is correct, sk. #writeStreamDo: is enough though, #utf8 is the default encoding
On 24 Jul 2019, at 22:16, sk via Pharo-users <pharo-users@lists.pharo.org> wrote:
From: sk <snoobabk@yahoo.ie> Subject: Re: [Pharo-users] P7 regression Date: 24 July 2019 at 22:16:50 GMT+2 To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
Hi Hilaire
I downloaded latest Dr Geo and took a quick look at how the files are saved. It looks like the xml contents are not encoded (in UTF-8) but simply written to a binary write stream, which means that when a WideString is written you should consistently get a badly encoded file.
You could test this out by changing this code DrGDirectoryLocal>>put: stream into: filename (location asFileReference / filename) ensureDelete binaryWriteStreamDo: [ :fileStream | fileStream nextPutAll: stream contents]
to rather be: DrGDirectoryLocal>>put: stream into: filename (location asFileReference / filename) ensureDelete writeStreamEncoded: 'utf-8' do: [ :fileStream | fileStream nextPutAll: stream contents ]
When I made this modification it worked for me i.e. the file was readable and correctly encoded.
Regards Carlo
On 24 Jul 2019, at 21:07, Hilaire <hilaire@drgeo.eu> wrote:
[...] stream := WriteStream on: (String new: 4000). DrGeoXml new app: self app; saveOn: stream. [...]
DrGeoXml>>saveOn: stream | doc writer root | doc := XMLDocument new version: '1.0'. writer := XMLWriter on: stream. root := XMLElement named: #drgenius. self writeFigureAsXmlTo: root. doc addElement: root. doc printXMLOn: writer.
The stream is passed to the XMLWriter, then it goes down to each items of the sketch to write its own XML node.
For example, to write its basic information as its name, where I have issue:
writeAsXmlTo: aNode "return the newly created element" | node | self rehash. node := XMLElement named: self basicType attributes: Dictionary new. node attributeAt: #type put: self nodeType; attributeAt: #name put: (name ifNil: ['']); attributeAt: #id put: self hash asString. self writeParentsAsXmlTo: node. aNode addElement: node. ^node
This code is as is since about 2005-2007
I will dig in it but it is strange.
Le 24/07/2019 à 18:45, Sven Van Caekenberghe a écrit :
But how do you write it to a file then ?
FileLocator desktop / 'hilaire.xml' writeStreamDo: [ :out | out << 'Les élèves Françaises ont 10 â¬' ].
(FileLocator desktop / 'hilaire.xml') contents.
">> 'Les élèves Françaises ont 10 â¬'"
-- Dr. Geo http://drgeo.eu
participants (1)
-
Sven Van Caekenberghe