Today's Smalltalk 4 You looks at using a mapping specification (in XML) so that the XML parser in VA will return Smalltalk objects rather than an XML document object. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:
You can also watch it on YouTube:
Today we'll look at setting up a mapping of XML to Smalltalk objects via a mapping file. We'll still be using the same orders example we've been looking at; this time, we have the additional mapping file:
To run this example, use:
and that code looks like this:
| mappingDOM mappingSpec result | self isDataInFile ifFalse: [self setupData]. self isMapInFile ifFalse: [self setupMap]. " Create a mapping spec from the order map " mappingDOM := AbtXmlDOMParser newNonValidatingParser parseURI: 'order.map'. "The image must contain Smalltalk classes conforming to the map." mappingSpec := AbtXmlMappingSpec fromMappingDOM: mappingDOM. " Parse the data " result := AbtXmlMappingParser newValidatingParser mappingSpec: mappingSpec; parseURI: 'order.xml'. ^result abtXmlMappedObject.
What that does is read the mapping data first, to construct a specification - that will be used when parsing the XML in order to get objects instead of a basic DOM object. The results should look like this:
If you take a look at the mapping XML file, you'll see that it's pretty easy to understand - setting one up yourself would not be a problem.
Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.
[st4u251-iPhone.m4v ( Size: 4067590 )]