The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Writing XML in Smalltalk code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Writing XML in Smalltalk code Posted: May 13, 2004 8:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Writing XML in Smalltalk code
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Michael Lucas-Smith

Advertisement

An interesting idea that has been popping up over and over again in the Smalltalk community is writing out XML or HTML using Smalltalk methods. I've seen it in Seaside and AIDA/Web, so I thought I'd throw in my own bone for fun.

So I ended up with something like the following:

XML.Document asMaker html: [:html |
	html head: [:head |
		head title: [:title | title +  'My Title'].
		head body: [:body |
			body +  'Hello World.'.
			body br.
			body +  'How are you?']].

Pretty simple huh? And it's all done using DoesNotUnderstand in Smalltalk. Instead of having to model all the different sorts of HTML and other XML's as is done in Seaside and AIDA/Web, this is just one class XMLMaker plus three class extensions to add some helper methods.

It also does namespaces:

XML.Document asMaker html: [:html |
	html xmlns: 'http://www.w3.org/xhtml'.
	html xmlns_foo: 'http://www.foo.com'.
	html foo_bar: [:bar |
		bar +  'Inside the bar in the foo namespace'].
	html body: [:body |
		body +  'Inside the body in the xhtml namespace']].

Check it out, it's XMLMaker in the public store repository. It works with a plain XML parser as well as the WithStyle Specialisation code if you have it loaded.

Read: Writing XML in Smalltalk code

Topic: Van Helsing Previous Topic   Next Topic Topic: Smokers and Unit-Testers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use