[Pharo-project] Writing API for XML (WAX) - Bibliography example

Hannes Hirzel hannes.hirzel at gmail.com
Sat Nov 6 11:36:11 CET 2010


Jaayer,

Thanks, I checked out

MCHttpRepository
    location: 'http://www.squeaksource.com/XMLSupport'
    user: ''
    password: ''

and looked at
XML-Parser-tg.101


Right version?


the class comment of XMLWriter



This class allows you to generate well-formed XML documents using an
API similar to Seaside's canvas and tag brush API.

Markup can be created by sending an instance any of the messages under
"writing markup." The messages that take no arguments return an
instance of an XMLMarkupWriter subclass. These objects can be
configured with messages like #name: and #attributeAt:put:. Sending
them #write or a specific writing message that accepts markup to embed
within (#content: or #internalSubset: for example) causes the markup
writer's configuration to be committed and its markup written to the
output stream. For markup writers that can have embedded markup, the
argument to the writing message can be a string, collection (of
strings and blocks), a block, or nil. The block passed in can
optionally take an argument, which will be the XMLWriter object that
created the markup writer object. Within the block you can generate
additional, child markup that will be contained by the parent.
Creating additional non-embedded markup will cause any unwritten
markup from a previous markup writer to be written, as will sending an
XMLWriter or XMLMarkupWriter #contents, #asString, #printOn:, or
#write.

Here is an example, which you can highlight and evaluate with cmd-p to
see the result:

	| writer |
	(writer := XMLWriter new) enablePrettyPrinting.
	writer xml.
	writer tag
			name: 'foo:bar';
			xmlnsAt: 'foo' put: 'http://foo';
			attributeAt: 'a' put: 'one';
			attributeAt: 'b' put: 'two';
			content: [
				writer tag: 'bar' content: [
					writer
						string: 'test';
						tag: 'baz';
						tag: 'foobar' content: 'test']]


Nice, as I know the Seaside html builder pattern. It is the same.


Remark: I think it should be in its own package

Instead of

    XML-Parser-Writers

I'd like to have

    XML-Writer

because writing has nothing to do with parsing.

However at this point it is minor cosmetics.

Another remark: An example using tags like name, author, title would
be helpful as well in the class comment because one sees more easily
what is going on.

For the current problem at hand I have started using WAX and I think I
will continue to do so. One reason it that I might want to port my App
to Java when finished prototyping in Smalltalk.


MCHttpRepository
    location: 'http://www.squeaksource.com/WAX'
    user: ''
    password: ''

I have not found XMLWriter tests whereas WAX has a considerable number of them.

As for XMLWriter, I surely will look at it again in a few months time.


Regards
Hannes

On 11/5/10, jaayer <jaayer at zoho.com> wrote:
>
>
>
>
> ---- On Wed, 03 Nov 2010 11:28:13 -0700 Hannes Hirzel  wrote ----
>
>>Is XMLWriter in the upcoming 1.2 image? It is not in the 1.1 image.
>>
>>--Hannes
>
> The new XML writer is in the more recent versions, from version 96 on, but
> at the moment you have to download it manually through Monticello or from
> the XMLSupport page on squeaksource.com, as the most recent Metacello
> configuration still points to v. 93. I'll try to update it shortly.
>
>
>




More information about the Pharo-project mailing list