Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Learn How To Populate A Database With Data Using An XML Document In This FireDAC Sample For Delphi

  • The FireDAC Database Connection creates a table (test_vs) and inserts data from an XML document using a FireDAC database connection.

Note: The connection to the database does not require authentication.

How to Use the Sample

  1. Navigate to the location given above and open Project1.dproj.
  2. Press F9 or choose Run > Run.
  3. Click the Button1 button and the grid will be populated with data.
  4. Click the Button1 button again to deactivate the TFDQuery component and stop showing the data.

Files

FileContains
Demo\Project1.dprojContains the project itself.
Demo\Unit1.dfmContains the code of the main form.
Demo\Unit1.pasContains the main form and the main code.
FireDAC.Comp.VSE.pasContains the code for the VSE class used for parsing the XML document.
FireDAC.Comp.VSEXML.pasContains the code for the VSEXML class used for XPath.

Implementation

  • When the TForm is created, a TFDConnection executes a DROP query against the test_vs table, creates the table, and populates it with data from an XML document.
  • The XML document is written at the beginning of the implementation part in the project.
  • Click the Button1 button on the main form to display (or not) the data in a TDBGrid, using a TFDQuery, a TDataSource, a TFDGUIxWaitCursor, and a TFDPhysSQLiteDriverLink.
  • The TFDQuery executes a SELECT query against the test_vs table and displays the results in a TDBGrid.
  • The project uses procedures which are found in the FireDAC.Comp.VSE.pas and FireDAC.Comp.VSEXML.pas units to interact with the XML document.
    • In the TForm creation procedure, a TFDVSEXMLManager (the FVS code variable) is instantiated and two TFDVSESchema (the oSch code variable) are created.
    • The two TFDVSESchema variables have the following TFDVSECMLFieldDefs fields: NameDataTypeSize, and XPathExpression. One TFDVSESchema is used for Request and the other one for Response. They are used for parsing the XML document.
    • The FVS Manager also adds a TFDVSESessions to allow the TFDQuery to execute the query.

If you want to check the original post with more information, refer to the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.VSE_Demo_Sample

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES