Understanding C$XML Terminology

The C$XML routine uses XML terminology that may not be familiar to you–terms like element, attribute, parent, child, and sibling. To understand the terminology of C$XML, consider the following XML file (line numbers added for discussion purposes):

 1 <?xml version="1.0"?>
 2 <bookfile
 3   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4   xsi:noNamespaceschemaLocation="bookfile.xsd">
 5   <transaction borrowDate="2001-10-15">
 6     <Lender phone="607.555.2222">
 7       <name>Doug Glass</name>
 8       <street>416 Disk Drive</street>
 9       <city>Medfield</city>
10       <state>MA</state>
11     </Lender>
12     <Borrower phone="310.555.1111">
13       <name>Britta Regensburg</name>
14       <street>219 Union Drive</street>
15       <city>Medfield</city>
16       <state>CA</state>
17     </Borrower>
18     <note>Lender wants these back in two weeks!</note>
19     <books>
20       <book bookID="123-4567-890">
21         <bookTitle>Earthquakes for Breakfast</bookTitle>
22         <pubDate>2001-10-20</pubDate>
23         <replacementValue>15.95</replacementValue>
24         <maxDaysOut>14</maxDaysOut>
25       </book>
26       <book bookID="123-4567-891">
27         <bookTitle>Avalanches for Lunch</bookTitle>
28         <pubDate>2001-10-21</pubDate>
29         <replacementValue>19.99</replacementValue>
30         <maxDaysOut>14</maxDaysOut>
31       </book>
32       <book bookID="123-4567-892">
33         <bookTitle>Meteor Showers for Dinner</bookTitle>
34         <pubDate>2001-10-22</pubDate>
35         <replacementValue>11.95</replacementValue>
36         <maxDaysOut>14</maxDaysOut>
37       </book>
38       <book bookID="123-4567-893">
39         <bookTitle>Snacking on Volcanoes</bookTitle>
40         <pubDate>2001-10-23</pubDate>
41         <replacementValue>17.99</replacementValue>
42         <maxDaysOut>14</maxDaysOut>
43       </book>
44     </books>
45   </transaction>
46 </bookfile>

When you call C$XML with the CXML-PARSE-FILE op-code, you get a handle to this entire file.

An "element" is a name that appears immediately after a less than sign (<), and terminated with a greater than sign (>) or by a forward slash followed by a greater than sign (/>). So "bookfile" (line 2) is the top-level element. "transaction" (line 5) is an element, as is "city" (lines 9 and 15 - these are two separate elements, both named "city").

There are two different ways in XML to signify that an element is finished:

  1. With a tag that is the element name preceded immediately by a less than sign and a forward slash (</).
  2. The corresponding greater than sign (>) is immediately preceded by a forward slash (/).

This sample has instances of the first method only. For example, the termination of the bookfile element is on line 46.

An "attribute" is included within the element description as a name followed by an equals sign (=), followed by a quoted string. The name is the attribute name, and the quoted string is the attribute value. There is no limit to the number of space-delimited attribute name/value pairs in an element. For example, the "transaction" element (line 5) has a single attribute whose name is "borrowDate" and whose value is "2001-10-15".

The "data" of an element is any non-element, non-comment text between the element start and end. Elements that end with a /> can't have data. And some elements don't have data. For example, the Lender element (line 6) has no data. The "street" element on line 8 has data of "416 Disk Drive".

A "child" of an element is an element one level below an element. For example, "Lender" is a child of "transaction", as is "Borrower". "name" is a child of "Lender", and there is a separate element named "name" which is a child of "Borrower". But neither of those "name" elements is considered a child of "transaction" because there is an element at a level between "name" and "transaction". There are two separate "city" elements, one of which is a child of "Lender", and the other a child of "Borrower". The elements between "city" and "Lender" are all at the same level as "city", which is why "city" is considered a child of "Lender".

A "parent" of an element is one who has that element as a child.

A "sibling" of an element is an element with the same parent.

So "transaction" is the parent of "Lender", "Borrower", "note" and "books" (lines 6, 12, 18 and 19, respectively). "Lender", "Borrower", "note" and "books" are all siblings.

A "record" is child of the top-level element.