XFILE Support
9.0D
Since data in an XML document is represented in a parent-child relationship, it cannot be easily handled using the standard FILE operations.
An XFILE is an abstract representation of an XML document that loads, examines, modifies, and saves XML data. A XFILE will create a memory resident representation of the elements inside of an XML document. The elements are broken into records and data fields.
A record is:
An XML element that has attributes
An XML element that has child elements
A data field is:
An XML element that has no attributes or child elements
An XML attribute of an XML element considered to be a record
If an XML element is considered to be a data field but repeats, it is a data field array.
If an XML element has both attributes and text, a data field named "Record_Text" is created to reference the text.
Each record can contain other records and data fields.
Records are then grouped into recordsets where the record name (element tag name) is used for the grouping. Records within records are also grouped into recordsets.
A XFILE corresponds to one record set. When a record set contains other recordsets, multiple XFILEs must be used to access the contained recordsets.
Example 1:
In this first example, the <PEOPLE> element tag is the XML root element. Also, the <PEOPLE> tag identifies a record set that contains a single embedded record set named <PERSON>. The <PERSON> tag identifies a record set that has two records. Each record in the <PERSON> record set has four data fields that are reference by the XML element names of PERSONID, NAME, ADDRESS, and PHONE. In this case, the first data field name PERSONID is an attribute for each record in the <PERSON> record set. The other data fields named NAME, ADDRESS, and PHONE are contained elements for each record in the <PERSON> record set.
|
Record Set 1: |
PEOPLE |
|
Contained Recordsets: |
PERSON |
|
Data Fields: |
None |
|
Record Set 2: |
PERSON with 2 records |
|
Contained Recordsets: |
None |
|
Data Fields: |
PERSONID, NAME, ADDRESS, PHONE |
The following PL/B code is a sample set of instructions for the example 1 XML structure that shows how XFILE data variables are used to read and update the data in the XML file.
Note the following about this example:
Because the XML file contains two recordsets, two XFILE data variables must be used to access and manipulate these recordsets.
The 'People' XFILE is opened to reference all elements in the XML data file.
A READ operation is executed for the People XFILE to access the next sequential record set and that record set is associated with the Person XFILE. This operation acts as if an implied open operation was performed for the embedded <PERSON> record set.
The READ operation for the Person XFILE is performed to retrieve the data fields identified by PERSONID=id and NAME=name. Notice, that the ADDRESS and PHONE data fields are not being retrieved.
The UPDATE operation for the Person XFILE is updating a single data field for the last Person record that was previously read successfully.
When the CLOSE for the Person XFILE is executed, the resources are released.
When the CLOSE for the People XFILE is executed, all of the current XML file data is written back to the physical disk data file that is associated with the People XFILE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example 2:
|
Record Set 1: |
LIBRARY |
|
Contained Recordsets: |
BOOK, MAGAZINE |
|
Data Fields: |
None |
|
Recordset 1: |
BOOK with 2 records |
|
Contained Recordsets: |
None |
|
Data Fields: |
NAME, TYPE |
|
Record Set 1: |
MAGAZINE with 1 record |
|
Contained Recordsets: |
None |
|
Data Fields: |
NAME, ISSUE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See Also: XML Support
![]() |