Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
![]() |
![]() |
![]() |
|
Delphi 6 XML Mapping Tool (XML Mapper)
Delphi 6 contains a lot of new and enhanced XML support, such as XML document programming, XML Data Binding Wizard, XML Mapper and BizSnap (SOAP/XML Web Services).
This is the third - and for now last - in a series of articles about Delphi 6 XML support.
This time covering the Delphi 6 XML Mapping Tool (also called the XML Mapper).
XML Mapper
Both as stand-alone tool and in the Tools menu of the IDE, you'll find a menu item called "XML Mapper".
An entire tool to map XML document to a DataSet representation! In the past few months, we've used a single
The XML Mapper File Open dialog tells you that is can load XML document files as well as data packet files (*.xml,*.cds), schema files (*.dtd,*.xdr,*.xsd), repository files (*.xrp) and transformation files (*.xtr).
The latter is actually a file type generated by the XML Mapper itself.
Let's just load the clinic.xml file from last month and see how a dataset mapping looks like.
Create and Test Transformation
Anyway, now there was just one thing left to do: click on the Create and Test Transformation button.
This results in a pop-up form with a DBGrid and apparently all records from the clinic.xml document but this time transformed into a ClientDataSet data packet.
As a result of the transformation, there were a couple of formats I could save with the XML Mapper.
For starters, I could save the resulting data package; the .xml ClientDataSet file version of the Clinic.xml file.
If you do that, you must make sure not to accidentally overwrite the XML document with an XML dataset of the same name! Alternately, you can decide to save the transformation information into clinic.xtr.
The latter can be used by the new XMLTransform components from the Data Access tab of Delphi 6 Enterprise.
XMLTransform
In the July issue of Delphi Developer, I already explained that there are three XML transformation components in Delphi 6 Enterprise.
For the clinic.xtr transformation information, we need the TXMLTransformProvider component, which uses the clinic.xtr in order to transform the original clinic.xml document into a ClientDataSet.
Very useful, because for the first time, we can actually access the information from the clinic.xml document using simple data-aware controls!
To demonstrate this, start Delphi 6 Enterprise (in case you've run the XML Mapper as stand-alone tool), and start a new project.
Drop a TXMLTransformProvider from the Data Access tab on your main form, and set the TransformationFile subproperty of the TransformRead property to the clinic.xtr file.
This will make sure that the transformation information from clinic.xtr is used whenever we try to read information (which will end up in the ClientDataSet provided by the TXMLTransformProvider component itself).
Apart from the transformation information, we should of course also make sure to set the XMLDataFile property to the clinic.xml document itself.
Once we've done this, we can drop a ClientDataSet component and point its ProviderName property to the XMLTransformProvider component.
Now, activate the ClientDataSet, and the transformation will start whenever the data from the XMLTransformProvider is requested (and since the ClientDataSet has the PacketRecords property set to -1 by default, it means that the entire XML document will be transformed right away).
To see the result data, we have to drop a DataSource and a DBGrid with a DBNavigator (for example) and connect the DataSource to the ClientDataSet and the DBGrid and the DBNavigator to the DataSource, like we've done for year now.
The output - at design-time - can be seen in the figure below (a bit similar to the preview from the XML Mapper itself).
ClientDataSet1.ApplyUpdates(-1)And now, if you close your application, the ClientDataSet will send the updates (if any) to the XMLTransformProvider component, which will use the transformation information stored in ClinicToXml.xtr to transform the datapacket back into an XML document. Ready to be processed by another virtual tier in a B2B environment. Delphi 6 BizSnap - makes e-business truly a snap!
For more recent information on Delphi for Win32 XML Programming, check out my Delphi 2010 XML, SOAP & Web Services courseware manual.