Visual Programming User Guide : Advanced Visual Programming : VA Smalltalk XML Support. : Using VA Smalltalk XML Support : Creating object instances from XML using mapping specifications
Creating object instances from XML using mapping specifications
The input deserialization API uses the following steps to create a VA Smalltalk object or objects from the contents of an XML input stream, a DTD, and a mapping specification defined in XML.
1. Parse the input XML file into an input DOM.
2. Create a mapping specification object from the XML mapping file.
3. Create objects from the input DOM and mapping specification objects.
If you are using the object cache, you can retrieve the mapping specification from the cache instead of performing step 2.
For more information on mapping exceptions goto the Handling Mapping Exceptions section.
Input Deserialization Methods
The following method is provided in the AbtDOMElement class:
mapUsing: anAbtXmlMappingSpec
Maps self using AbtXmlMappingSpec.
The following methods are provided in the AbtDOMDocument class:
mapElement: elementTagName using: anAbtXmlMappingSpec
Maps the first element of name, elementTagName. using AbtXmlMappingSpec. Use the mapElement: using: method to specify a name you want to map and return the element of that name.
mapElements: elementTagName using: anAbtXmlMappingSpec
Maps elements of name, elementTagName using AbtXmlMappingSpec. Use the mapElements:using: method to specify a name you want to map and return all the elements of that name.
mapUsing: anAbtXmlMappingSpec
Maps the root element of the DOM using AbtXmlMappingSpec.
Input Deserialization Example
The following Smalltalk code creates a VA Smalltalk object from the contents of an XML input stream, a DTD, and an interface mapping specification:
| domSource mapSpec orderObject|
"Parse the input XML"
domSource :=
(AbtXmlDOMParser newValidatingParser)
parseURI: 'd:\workspce\xml\hld\serialize\order.xml'.
"Create a mapping specification from the mapping XML"
mapSpec := AbtXmlMappingSpec from: 'd:\workspce\xml\hld\serialize\order.map'.
"Optional, add DTD to the object cache "
domSource dtd addToXmlObjectCache.
"Create objects from input DOM by applying rules from the mapping spec"
orderObject := domSource mapUsing: mapSpec.
Last modified date: 01/29/2015