Because XML historically was designed for electronic publishing, a single, self-contained section of XML is called a document, even though it may contain arbitrary data. GPL parses existing XML text documents and creates new XML documents, by converting them to and from a tree structure stored in the controller’s memory. A parsed XML document consists of nodes for items in the document, arranged in a tree that reflects how items in the document are nested. The tree is constructed using a subset of the Document Object Model (DOM) Core Interfaces as described in: http://www.w3.org/TR/REC-DOM-Level-1 and methods similar to those found in Visual Basic.NET.
The top-level node in a DOM tree is the document node. There is only one such node for each document. The organization of child nodes in the document corresponds to the organization of the data in the XML text file. The various child nodes contain the names of the data sections and also the data from the text document.
All nodes have a type. Some common types are shown in Table 19-43.
| Node Type | Description |
|---|---|
|
Document |
The top-level node in a document. Only one such node exists per DOM tree. |
|
Element |
The basic node type. An element corresponds to an XML tag that begins with “<”. For example the element named sample begins with “<sample>” and ends with “</sample>”. |
|
Attribute |
An attribute of a node. It normally has either a document or element as its parent. In XML text, attributes are embedded inside the element name start tag. For example an attribute named color of element sample appears as <sample color=”value”>. |
|
Text |
The data contents of an element or attribute. It holds whatever is between two element tags, or the “value” of an attribute. |
|
CDATA section |
A special text node that allows special characters in the data without encoding them. The data starts with “<!CDATA[” and ends with “]]>”. |
|
Comment |
A special text node that contains a comment not considered part of the document data. The comment data begins with “<?--“ and ends with “-->”. |
|
Processing Instruction |
A special text node that contains processor-specific information. The information data begins with "<?" and ends with "?>". |
When an XML text document is parsed, GPL creates a new DOM tree in the controller’s memory with child nodes that contain all the parsed data. The XML classes and methods that are provided in GPL allow an application program to efficiently access the data contained in the tree. If desired, the data in the tree may be modified and written back out in the XML text format.
In order to create an XML text file, a GPL program must first create a new document tree in the controller’s memory and add nodes that contain the desired data. An XML method can then be executed that converts the tree in memory to the XML text format.