[vwnc] XML pretty print

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] XML pretty print

Steffen Märcker
Hi,

how can xml be written using "pretty print"?

Thanks!
Steffen
_________________________________________________________________________
In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten!
Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] XML pretty print

Reinout Heeck-2
Steffen Märcker wrote:
> Hi,
>
> how can xml be written using "pretty print"?
>  

The standard #printString of XML.Node returns a formatted string:

  dom := XMLParser
      processDocumentInFilename: 'c:\Projects\repositories.xml'
      beforeScanDo: [:parser | parser validate: false].
  dom printOn: Transcript


If you want to do more fancy things you can build your own SAX driver to
generate pretty output from xml being parsed, for an example see
Tools.FileTools.XMLSourceViewer>>parseXMLFrom:writingTo:


Another natural thing to do would be to create a Visitor that walks the
dom nodes and pretty prints them, see #saxDo: & #nodeDo: on the Node
hierarchy for not-quite-Visitor support.


Enjoy,

R
-



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] XML pretty print

Steven Kelly
In reply to this post by Steffen Märcker
Steffen Märcker wrote 19 August 2008 12:44:
> how can xml be written using "pretty print"?

If you want to write an XML.Element, xml, to a file, try something like this:

writeXML: xml toFilename: filename
        | ws |
        ws := (filename withEncoding: #'utf-8') writeStream.
        ws
                nextPutAll: '<?xml version="1.0" encoding="UTF-8"?>';
                cr.
        [xml printOn: ws] ensure: [ws close]

You could also look at "xml canonicalPrintString"

HTH,
Steve

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc