> Sent: Friday, September 15, 2017 at 4:30 PM
> From: "Jimmie Houchin" <jlhouc...@gmail.com>
> To: "Any question about pharo is welcome" <pharo-users@lists.pharo.org>
> Subject: Re: [Pharo-users] Writing XML
>
> I didn't pay attention to this previously. But I just noticed that using 
> #printToFileNamed:   preserved the DOM tree's original line ending where 
> as previously I had to insure the the XMLWriter #lineEnding was changed 
> from defaultLineEnding to canonicalLineEnding. The original document 
> used LF and not CR.

To clarify, #printToFileNamed: and company use CRLF on Windows and LF 
elsewhere. XMLWriter uses Pharo's LE by default (CR), but it will use the 
preferred LE of your platform (LF or CRLF) with 
#enablePlatformSpecificLineBreak, LF when canonical XML 
(https://www.w3.org/TR/xml-c14n) is enabled, or whatever LE you want with 
#lineBreak:.

You can use #printToFileNamed:beforeWritingDo: with a block that sends 
#lineBreak: to the writer argument to get a custom LE when printing a DOM tree 
to a file.

> Overall this was a nice win.
> It cleaned up my method to save the file and reduced 7 lines to 2.
> Nice.  :)
> 
> Thanks.
> 
> Jimmie
> 
> 
> 
> On 09/15/2017 09:29 AM, monty wrote:
> > If you want to write a DOM tree to a file, send #printToFileNamed: (or a 
> > related message like #canonicallyPrintToFileNamed: or 
> > #printToFileNamed:beforeWritingDo:) to the root. See the XMLNode "printing" 
> > category for more. This will automatically encode the file with the 
> > encoding the XMLDocument>>#encoding attribute specifies (if recognized), 
> > and it's portable across Pharo, Squeak, and GemStone. Use 
> > #parseFileNamed:/#onFileNamed: to get portable automatic file decoding when 
> > parsing.
> >
> >> Sent: Wednesday, September 13, 2017 at 1:02 PM
> >> From: "Jimmie Houchin" <jlhouc...@gmail.com>
> >> To: "Any question about pharo is welcome" <pharo-users@lists.pharo.org>
> >> Subject: [Pharo-users] Writing XML
> >>
> >> Hello,
> >>
> >> I am attempting to read and write an XML document.
> >>
> >> Currently I have parsed the document successfully. I have basic
> >> navigation and have learned how to modify the XMLDocument.
> >>
> >> Now I want to write the modified document back to the file system.
> >> What I have tried so far is:
> >>
> >> writer := XMLWriter new.
> >> xmldoc document writeXMLOn: writer.
> >> writer stream.
> >> f := File openForWriteFileNamed: '/home/jimmie/xmldoc.xml'.
> >> f nextPutAll: (writer write contents).
> >> f flush.
> >> f close.
> >>
> >> It does write an xml document to the file system. However, it has
> >> exploded in size. The original is 28mb and is in UTF-8. The newly
> >> written file is 112mb and is UTF-32.
> >>
> >> I do not know why the change in encoding or how to correct or manually
> >> set the encoding.
> >>
> >> Any help in understanding how to correctly write an XML document that I
> >> have read and minimally modified would be greatly appreciated.
> >>
> >> Thanks.
> >>
> >> Jimmie
> >>
> >>
> 
> 
> 

Reply via email to