[squeak-dev] Writing API for XML (WAX) - Bibliography example
Hannes Hirzel
hannes.hirzel at gmail.com
Mon Nov 1 21:58:24 UTC 2010
Hello
I read the post by Stephane Ducasse about writing XML (see below) with
a bibliography example.
Recently I (re)-discovered the port to Squeak/Pharo of the Writing API
for XML (WAX) (http://java.ociweb.com/mark/programming/WAX.html) and
could put it to good use for writing an XML file a bit more complex
than the bibliography example.
>From the web site
WAX has the following characteristics:
* focuses on writing XML, not reading it
* requires less code than other approaches
* uses less memory than other approaches
(because it outputs XML as each method is called rather than
storing it in a DOM-like structure and outputting it later)
* writes all XML node types
* always outputs well-formed XML or throws an exception unless
running in "trust me" mode
* knows how to associate DTDs, XML Schemas and XSLT stylesheets
with the XML it outputs
* is well-suited for writing XML request and response messages for
REST-based and SOAP-based services
However I do not know how far these points apply to the Squeak/Pharo port.
http://www.squeaksource.com/WAX
It needs the VB Regex package (http://www.squeaksource.com/Regex)
As an exercise I did the code to produce the example Stephane gave. It
worked fine; see below.
Regards
Hannes
==========================================================
WAX new
stream: (FileStream newFileNamed: 'myBibliography.xml');
writeXMLDeclaration: #1.0;
start: 'BDBase';
attr: 'date' value: '25 May 2010';
attr: 'note' value: 'nil';
start: 'bd';
attr: 'authors' value: 'Larcenet';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '25 March 2006';
attr: 'entryNumber' value: '1';
attr: 'number' value: '1';
attr: 'original' value: 'true';
attr: 'serie' value: 'Nic oumouk';
attr: 'serieComplete' value: 'false';
attr: 'title' value: 'Total souk pour nic oumouk';
attr: 'year' value: '2005';
end;
start: 'bd';
attr: 'authors' value: 'Greg';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '5 May 2006';
attr: 'entryNumber' value: '2';
attr: 'notes' value: 'sur le 4eme de couv aventure a manhattan';
attr: 'number' value: '9';
attr: 'original' value: 'true';
attr: 'serie' value: 'Achille Talon';
attr: 'title' value: 'Les petits desseins d''Achille Talon';
attr: 'year' value: '1974';
end;
start: 'bd';
attr: 'authors' value: 'Greg';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '5 May 2006';
attr: 'entryNumber' value: '3';
attr: 'notes' value: 'sur la couverture une histoire du journal tintin';
attr: 'number' value: '13';
attr: 'original' value: 'true';
attr: 'serie' value: 'Achille Talon';
attr: 'title' value: 'Pas de pitié pour Achille Talon';
attr: 'year' value: '1976';
end;
end;
close.
==========================================================
Output
<?xml version="1.0" encoding="UTF-8"?>
<BDBase date="25 May 2010" 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"/>
</BDBase>
==========================================================
On 10/31/10, stephane ducasse <stephane.ducasse at free.fr> 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
>
More information about the Squeak-dev
mailing list
|