Writing and reading an XML file
Last updated at 7:34 pm UTC on 15 September 2017
Writing an XML file
doc := XMLDocument new.
stream := FileStream fileNamed: 'MyXml.xml'. "specify the stream"
writer := XMLWriter on:stream. "specify the writer"
writer initialize.
"Code below describes how you could write an xml element with a tag "
elmt := XMLElement named: 'user' attributes: Dictionary new.
"add 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.
Produces the following file
<user>
<name>rao</name></user>
Read this file
See also
http://stackoverflow.com/questions/17538167/how-to-pretty-print-xml-from-smalltalk