XML Functionality Using XMLAdapters

With the XMLAdapter, XMLTable, and XMLField classes, Visual FoxPro enhances its existing XML features and its compatibility with XML DiffGram and .NET Framework ADO.NET DataSet formats. The XMLAdapter, XMLTable, and XMLField classes require Microsoft XML Core Services (MSXML) 4.0 Service Pack 1 (SP1).

For more details and download information, see Microsoft XML Core Services 4.0 SP1 on the MSDN Library Web site at https://msdn.microsoft.com/downloads/.

Visual FoxPro supports hierarchically formatted XML for the following:

  • XML files that have associated schema, either inline or external, as implemented by ADO.NET DataSets based on the .NET Framework
  • Microsoft XML Data Reduced Schema (XDR) as used by Microsoft SQL XML
  • ADO Recordset schemas that are produced when an ADO Recordset is saved as XML to a file or stream

Visual FoxPro can factor an XML file representing a collection of different and possibly related tables, such as an ADO.NET DataSet object, into separate Visual FoxPro cursors. Usually, this file contains data from a database management system (DBMS) with the structure of Parent > Child > Child. The XML can also have a nested format such as Parent > Child, Parent > Child, or a serial format such as Parent-Parent, Child-Child.

When you have hierarchical XML that represents a single table resulting from a multiple-table SQL JOIN command, Visual FoxPro creates only one cursor.

For more information about XML DiffGram and ADO.NET DataSet formats, see the .NET Framework SDK on the MSDN Library Web site at https://msdn.microsoft.com/library/.

ADO.NET DataSets

In the .NET Framework, ADO.NET is a set of classes that expose data access services to the programmer working with .NET. ADO.NET provides consistent access to data sources such as Microsoft SQL Server and other data sources exposed through OLE DB and XML.

The ADO.NET DataSet is used as the primary class for manipulating data and encapsulates data as XML. An ADO.NET DataSet object can produce XML in several ways:

  • By returning the entire ADO.NET DataSet to the calling application.

    This method returns all rows in the original query in XML DiffGram format with inline schema and update, insert, and delete operations as indicated. Rows that remain unchanged do not have the diffgr:hasChanges attribute.

    When a DataSet object returns to the calling application from a method in an application that uses the .NET Framework and returns ADO.NET DataSet objects, it is always serialized, or converted, into XML. Visual FoxPro can convert this XML into cursors, which you can then manipulate in a Visual FoxPro application.

  • By returning only changes to the ADO.NET DataSet to the .NET-based application.

    This method returns only those rows, in XML DiffGram format, that were modified, added, or deleted.

    If the ADO.NET DataSet object contains changes, they are marked with the attributes, DiffGram:hasChanges="modified" or DiffGram:hasChanges="inserted". For those records marked as "modified", the previous values appear in the section, diffgr:before. Records that are deleted appear only in the diffgr:before section and not in the main section of the DiffGram.

  • By using the ADO.NET DataSet GetXml and GetXMLSchema methods to return XML as a .CLR stream or string type.

  • By using the ADO.NET DataSet WriteXml and WriteXmlSchema methods write the ADO.NET DataSet as XML to a file with inline schema, without schema, or separate schema.

See Also

Objects, Collections, and Classes | XMLAdapter Class | XMLTable Class | XMLField Class | Visual FoxPro and XML Schema Data Type Mapping