1

Somewhat lost here.... Using Delphi XE2 cross-platform (Win/OSX), I want to retrieve some XML through a call to a RESTful service, parse it, and then display selected elements in a scrollable grid control. In other words, I need to treat the incoming XML as a data packet and hook it up to a grid.

I am able to retrieve the XML at this point using a TidHTTP component and drop it into a memo control just to inspect it; all looks good. However, I don't understand the best way to wire this to a grid. When running in Firemonkey mode with OSX as a target platform, the grid types do not seem to include a data-aware one. I don't actually need a live connection to a datasource per se, as the grid contents will be read-only, so I am willing to manually populate the grid if I have to. What's the easiest way to ingest the XML and get it into my grid?

Probably dumb questions, but XE2 has so many web-oriented controls and technologies that I am just lost. Thanks!

RRUZ
  • 134,889
  • 20
  • 356
  • 483
user1248816
  • 109
  • 2
  • 8

2 Answers2

1

You should convert the XML to an objectlist, then use LiveBindings to hook it up to a grid. It's a two step process. You'll find plenty of examples for each step.

Brave Cobra
  • 684
  • 3
  • 11
  • Thanks - not finding examples readily but I'll keep searching. Am I correct that TXMLTransformProvider is only available for Win, not OSX? In further reading, this would seem to be the most straightforward approach, but I don't even see the component in the palette and when I create it in code I can't compile for the OSX target. Windows works... – user1248816 Mar 15 '12 at 15:16
0

An "almost" codeless way to do it is using XSLT and a TClientDataSet:

  • transform the incoming XML to a TClientDataSet-compatible XML data packet using XSL
  • load the XML data packet in a TClientDataSet
  • fill the grid by iterating over the rows and columns of the dataset

XSLT is kind of a swiss army knife for XML - it is a (XML-based) language used for the transformation of XML documents to other formats (HTML, plain text, PDF...).

The advantage of this solution is that no intermediary code (objects) have to be coded and instantiated - it is the shortcut to read the HTML response and convert to a dataset.

A quick search on the web found this example.


However I have not checked if XSLT is already available in Delphi for OSX.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • Does Delphi provide a mechanism to generate an XSLT for this purpose? – user1248816 Mar 15 '12 at 15:16
  • If I understand correctly, the XML Data Binding Wizard uses XSL internally. It is included in Enterprise and higher only. See also http://docwiki.embarcadero.com/VCL/XE2/en/Xmlxform.TXMLTransformProvider – mjn Mar 15 '12 at 17:19