[ Pobierz całość w formacie PDF ]
.This time,the result will be as required, with both Title fields having a specified Length of themaximum value of their original value.That s okay, at least no field values will betruncated or clipped.Finally, to create and test the transformation and verify that this time nothing wentwrong, we should click the big Create and Test Transformation button.This willshow a form with the generated dataset (along with the contents from the XMLdocument inside the dataset).We could have noted from Figure 13.12 that theSection dataset is actually a nested dataset (a field of type TDataSetField).So at first,we only see the Title and Section of the chapter and have to click the ellipsis to geta second form with a grid that shows the three sections from the chapter, seeFigure 13.13.FIGURE 13.13 Create and Test Transformation.After we ve verified that the transformation is okay, we should save the currenttransformation information in the suggested ToDp.xtr file.Next, if you also want tobe able to transform the dataset back to an XML document, you should click theradio button to set the direction from XML to Datapacket to Datapacket to XML.Then, click the Create and Test Transformation button, which will result in an XMLdocument this time, and save the transformation information again, this time inToXml.xtr.At this time you can close the XML Mapper, because it has performedits task.TransformingArmed with the BizSnap.xml file and the two ToDp.xtr and ToXml.xtr transformationinformation files, we can now convert the XML document to a dataset, makechanges to the data inside the dataset, and convert it back to an XML documentagain.16 0672324806 CH13 12/12/02 2:38 PM Page 486486 CHAPTER 13 XML Document Programming and XML MapperWe can use the same XML Document component: the BizSnap.xml file.Now weshould access it using the Transform components from the Data Access tab of thecomponent palette.From left to right, we have the TXMLTransform,TXMLTransformProvider, and TXMLTransformClient components.The TXMLTransform can be used to transform an XML document into a datapacket orback.The TXMLTransformProvider can be used to transform an XML document into adata packet that is provided to a TClientDataSet (or a TXMLBroker component) compo-nent.It can be exported in a DataSnap application, as I ll show in the last section ofthis chapter.Finally, the TXMLTransformClient component converts the dataset from aTDataSetProvider back into an XML document.Transformation DemonstrationTo demonstrate this transformation process, start a new application and drop aTXMLTransformProvider component from the Data Access tab on the main form.Setthe TransformationFile subproperty of the TransformRead property to the ToDp.xtrtransformation file, which is used when XML information is read so it can be trans-formed into a dataset data packet, which will be provided to a receivingTClientDataSet component.If you also want to update the XML document again, wemust set the TransformationFile subproperty of the TransformWrite property to theToXml.xtr transformation file, which is used when the connecting TClientDataSetcalls the ApplyUpdates method back through the TXMLTransformProvider all the wayto the XML document.Apart from the transformation information, we should makesure to set the XMLDataFile property to the BizSnap.xml document itself.I often use.xtr and.xml files in the same directory as my executable, which means that I canremove the directory information in front of each of these three filenames (leavingonly ToDp.xtr, ToXML.xtr, and BizSnap.xml).Therefore, I can easily move the applica-tion and accompanying files around and to other machines.Anyway, after we ve specified the external files to use, we can drop a TClientDataSetcomponent on the main form as well, call it cdsChapter and point its ProviderNameproperty to the TXMLTransformProvider component.We can open cdsChapter, whichwill request data from the XMLTransformProvider, and as a side-effect, start the XMLtransformation.Right-click the cdsChapter component to start the Fields Editor, right-click again and do Add All Fields to create a persistent Title field as well as the nesteddataset Section.Now, drop another TClientDataSet component, and call it cdsSection.Obviously, thisone will be used to connect to the nested dataset Section, so make sure to assign theDataSetField property to the cdsChapterSection field.To see the transformed data,drop two TDataSource components (one for each ClientDataSet), a TDBEdit (for theTitle field of cdsChapter) and a DBGrid (for the entire cdsSection)
[ Pobierz całość w formacie PDF ]