0

I have in my application Builder C++(embarcadero) a dbgrid.. I would like to populate with data from XML file..

before to populate a dbgrid, we should convert the xml file to xml datapacket. To do that, you must define the relationship between the metadata in a data packet and the nodes of the corresponding XML document. A description of this relationship is stored in a special XML document called a transformation. In this step we can use Mapper tool to create a transformation.

In my case i have a xml file

    <result name="response" numFound="3098" start="0">
    <doc>
        <str name="Document Extension">PST</str>
        <str name="Document Page Count">1</str>
        <str name="DocID">1</str>
        <str name="lastModifiedIdx">2015-02-02 09:40:29.0</str>
    </doc>
    <doc>
        <str name="Document Extension">PST</str>
        <str name="Document Page Count">1</str>
        <str name="DocID">2</str>
        <str name="lastModifiedIdx">2015-02-02 09:39:53.0</str>
    </doc>
    </result>

with this structure(element str with attribute name), i can to load correctly in my Mapper tool to create a xstr file..

I would like to transform this file to some structure

   <doc>
        <Document Extension>PST</Document Extension>
        <Document Page Count>1</Document Page Count>
        <DocID>2</DocID>
        <lastModifiedIdx>2015-02-02 09:39:53.0</lastModifiedIdx>
    </doc>

see this link for more information : http://docwiki.embarcadero.com/RADStudio/XE5/en/Converting_XML_Documents_into_Data_Packets

Any idea?

manlio
  • 18,345
  • 14
  • 76
  • 126
  • I am not sure which question you are asking - do you wish to populate a grid, or do you wish to transform some xml? – Hugh Jones Feb 09 '15 at 22:43
  • i need to populate a dbgrid with xml file... "the only way can i see is to transform xml to xml datapacket." –  Feb 09 '15 at 22:55
  • 1
    The link you supplied tells you exactly how to do this, in the sections with the heading *Obtaining the resulting data packet* and *Converting user-defined nodes*. What part of that is unclear to you? Once you've provided the transformation, you simply assign the appropriate properties to a `TClientDataSet` (as shown in the example), and then attach a `TDataSource` to that `TClientDataSet`, and assign that `TDataSource` to the `TDBGrid.DataSource` property. Set the `TClientDataSet.Active` property to true (or use `TClientDataSet->Open;`). – Ken White Feb 09 '15 at 23:00
  • all steps(client dataset and datasource) is after then you create a xtr file with the mapper tool.. but when we need to use Mapper, we should have a structure and element without attribute to create xtr file(the transformation).. i need to transfom my xml (first src) to my xml (second code).. –  Feb 09 '15 at 23:19
  • 1
    As Ken said - the instructions are available in the link you provided. You are quite right that the business of connecting a ClientDataSet to a grid comes later. So what is the difficulty with the transformation step? – Hugh Jones Feb 10 '15 at 00:41
  • but - as an aside - a transform is not the ONLY way to solve this problem; you could parse the original xml and populate a ClientDataset directly. – Hugh Jones Feb 10 '15 at 00:59
  • i need to transfom my xml (first src) to my xml (second code).. in this case i can use mapper to generate xstr file to load on xmltransform... @HughJones how to populate ClientDataset directly? –  Feb 10 '15 at 10:16
  • i) Create a clientdataset with the fields you require ii) Open the xml iii) `insert` each record into the ClientDataset – Hugh Jones Feb 10 '15 at 16:11
  • i) the field is variable element in ... how t do that?! –  Feb 11 '15 at 19:39
  • @HughJones you dont understant the situation.. i have a field element variable .. –  Feb 11 '15 at 19:59
  • I do understand - I have done this type of thing many times. You can easily create a ClientDataset with the fields `id, extension, pages, lastmodified`. (Read the articles by Carey Jensen on how to create clientdatasets). To parse your xml file read some of the sources from http://stackoverflow.com/questions/263419/libraries-and-tutorials-for-xml-in-delphi. – Hugh Jones Feb 12 '15 at 09:32
  • Aha! - I think I see what your confusion is - 'name' is an `attribute` of the str elements but 'PST', '1' etc are the `text` of the str elements – Hugh Jones Feb 12 '15 at 10:00

0 Answers0