Browse DevX
Sign up for e-mail newsletters from DevX


The VFP 8 XMLAdapter Class

Visual FoxPro 8.0 introduces a whole new way to work with eXtensible Markup Language (XML). The XMLAdapter class works with hierarchical XML, provides an object-oriented approach to working with XML data, and leverages your familiarity with tables and fields in the way it exposes the XML contents.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

he new XMLAdapter class in VFP 8 greatly enhances your ability to work with XML data sources, including hierarchical XML documents, such as .NET DataSets. Cathi explains how this and related new classes open new possibilities for your applications.

Many developers have come to realize the enormous potential of a platform-neutral way to exchange structured data over the Intranet/Internet by using XML. XML makes it possible to integrate your applications with others, even if they're using platforms and systems completely different than yours. Integrating business applications has become an essential need. XML is the key to this kind of integration.

The XMLAdapter class provides new support for working with XML. One capability of this new class is support for hierarchical XML. This means that an XML file that represents a collection of different and potentially related tables, such as a Windows .NET DataSet, will render into separate Visual FoxPro cursors.

Flexibility and control over data is enhanced by being able to control the schema of the XML that is created, as well as control the data types that the cursor creates from the XML of the schema. This allows you to load in the XML, change the schema, then generate the cursor. In addition, you can take a cursor in memory, control the schema, and then generate the XML in a different format.

Working with XML in Visual FoxPro 8.0 vs. Visual FoxPro 7.0
The XMLTOCURSOR()/CURSORTOXML() functions that were new to Visual FoxPro 7.0 restricted you to working with XML files that contained data for only one table. If more than one table is contained in the XML file, you need to parse through the file manually. In addition, you don't have the full control of the schema that was contained in the XML file to change the data types before converting the XML to a Visual FoxPro cursor. When the XML was generated from the cursor, you don't have control of the schema that is generated.

The XMLAdapter class in Visual FoxPro 8.0 greatly enhances XML support to provide you with the ability to work with multiple tables in one XML file, and the compatibility of working with XML from different sources. The schema can be modified to allow you control over how data is converted to a cursor and how the XML is generated from Visual FoxPro cursors.

Introduction to the XMLAdapter, XMLTable, and XMLField Classes
The XMLAdapter class allows you to load XML from an XML source, parses the XML Schema (when it exists), and add one or more XMLTable object(s) to its tables collection. In turn one or more XMLField object(s) are added to the Fields collection of each XMLTable.

Integrating business applications has become an essential need. XML is the key to this kind of integration.
XMLAdapter class can also create an XML document representing the contained tables and fields that have been populated. XMLAdapter class includes two other child member classes: XMLTable and XMLField. These provide the ability to walk through the schema programmatically and access or set information.

The primary functionality that the XMLAdapter Class provides is to retrieve XML via the LoadXML() method, then parse the XML via the contained XML Schema, as appropriate, into one or more XMLTable objects, which in turn contain XMLField object(s).

The XMLTable class is a collection of all tables contained in the XML and functions to allow you to step through the table to perform procedures on them.

The collection of XMLTable objects describes the XML as a Visual FoxPro cursor or cursors, along with any relational information. The XMLAdapter does not store the actual XML schema or content, but does store object references to them.

The developer may then use the XMLTable.ToCursor() method to produce a cursor that contains the data of all the fields represented by the child member XMLField collection.

The XML and XML Schema data retrieved via the XMLAdapter.LoadXML() method remains in memory until replaced via a subsequent call to LoadXML(), or when it is specifically released by calling the ReleaseXML() method.

The XMLField class is a collection created for each XMLTable and contains all the fields in the table. The developer can iterate through the field objects and make any necessary changes. There are no methods associated with the XMLField class.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date