[Newbies] Squeak and XML

Kenneth Payne kmp at atrium.fsnet.co.uk
Sat Oct 7 13:13:38 UTC 2006

On Thursday 05 October 2006 02:27, mike.vidal at gmail.com wrote:
> Does anyone have a link to current information about how to work with
> XML with Squeak?
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

Try the Squeak Swiki - search for YAXO. 

The YAXO and XML article includes these useful examples of using the DOM 

Writing to a file called MyXml.xml

"Code below describes opening a stream and writer and associating the writer 
with XMLDocument"

doc := XMLDocument new.
stream := FileStream fileNamed: 'MyXml.xml'. "speicifying the stream"
writer := XMLWriter on:stream. "specifying the writer"
writer initialize.

"Code below describes how you could write an xml element with a tag "
elmt := XMLElement named: 'User' attributes: Dictionary new.

"adding the attribute tags and values to the "
childElmt := XMLElement named: 'Name' attributes: Dictionary new.
childElmt addContent: (XMLStringNode string: ('rao')). "adding a tag called 
Name with the value 'rao'"
elmt addElement: childElmt.

doc addElement: elmt.
doc printXMLOn: writer.
stream close.

Reading from MyXml.xml
f := FileStream fileNamed: 'xml.xml'. "opening a stream"
doc := XMLDOMParser parseDocumentFrom: f.
f close.
xmlUser := (doc elements) at: 1. "now you have the entire user data"

"readng the name"
elmt := xmlUser firstTagNamed: #Name.
userName := elmt contentString.

Notice how once you call the parseDocumentFrom: you don't need to have the 
stream open because XMLDOMParser builds tree right away from the given 

Hope this helps.

- Ken

More information about the Beginners mailing list