XML Background
This topic provides a quick summary of XML terms and concepts, as a refresher for users working with the Caché %XML classes. It is assumed that the reader is familiar with the basic syntax of XML, so this topic is not intended as a primer on XML. It does not, for example, describe the syntax or list reserved characters. However, it does provide a list of the terms with short definitions, as a reference.
ID="QD5690"
Attributes reside within elements, as shown below, and an element can have any number of attributes.
<Patient ID="QD5690">Cromley,Marcia N.</Patient>
<myelementname><![CDATA[ Non-validated data goes here. You can even have stray "<" or ">" symbols in it. ]]></myelementname>
A CDATA (character data) section cannot contain the string ]]> because this string marks the end of the section. This also means that CDATA sections cannot be nested.
Note that the contents of a CDATA section must conform to the encoding specified for the XML document, as does the rest of the XML document.
<!--Output for the class: GXML.PersonNS7-->
Empty content model (no child elements or text nodes are permitted)
Simple content model (only text nodes are permitted)
Complex content model (only child elements)
Mixed content model (both child elements and text nodes are permitted)
In all cases, the element may or may not have attributes; the phrase content model does not refer to the presence or absence of attributes in the element.
<Person xmlns="http://www.person.org"> <Name>Isaacs,Rob G.</Name> <DOB>1981-01-29</DOB> </Person>
Because this namespace declaration does not use a prefix, the <Person>, <Name>, and <DOB> elements all belong to this namespace.
Note that the following XML, which does not use a default namespace, is effectively equivalent to the preceding example:
<s01:Person s01:xmlns="http://www.person.org"> <s01:Name>Isaacs,Rob G.</s01:Name> <s01:DOB>1981-01-29</s01:DOB> </s01:Person>
<Patient>Cromley,Marcia N.</Patient>
An element can have any number of attributes and any number of child elements.
An empty element can either include a start tag and an end tag, or just a single tag. The following examples are equivalent:
<EndDate></EndDate> <EndDate/>
In practice, elements are likely to refer to different parts of data records, such as:
<Student level="undergraduate"> <Name>Barnes,Gerry</Name> <DOB>1981-04-23</DOB> </Student>
&characters;
Attributes are global or local in the same way.
You include a namespace declaration with one of the following syntaxes:
xmlns="your_namespace_here" pre:xmlns="your_namespace_here"
In either case, the namespace is used only within the context where you inserted the namespace declaration. In the latter case, the namespace is associated with the given prefix (pre). Then an element or attribute belongs to this namespace if and only if the element or attribute also has this prefix. For example:
<s01:Person xmlns:s01="http://www.person.com"> <Name>Ravazzolo,Roberta X.</Name> <DOB>1943-10-24</DOB> </s01:Person>
The namespace declaration uses the s01 prefix. The <Person> element uses this prefix as well, so this element belongs to this namespace. The <Name> and <DOB> elements, however, do not explicitly belong to any namespace.
<?xml-stylesheet type="text/css" href="mystyles.css"?>
<?xml version="1.0" encoding="UTF-8"?> <Root> <s01:Person xmlns:s01="http://www.person.com" GroupID="J1151"> <Name>Frost,Sally O.</Name> <DOB>1957-03-11</DOB> </s01:Person> </Root>
Here, the namespace declaration uses the s01 prefix. There is no default namespace. The <Person> element uses this prefix as well, so that element belongs to this namespace. There is no prefix for the <Name> and <DOB> elements or the <GroupID> attribute, so these do not explicitly belong to any namespace.
In contrast, consider the following case where the elements and attribute of <Person> are qualified:
<?xml version="1.0" encoding="UTF-8"?> <Root> <Person xmlns="http://www.person.com" GroupID="J1151"> <Name>Frost,Sally O.</Name> <DOB>1957-03-11</DOB> </Person> </Root>
In this case, the <Person> element defines a default namespace, which applies to the child elements and the attribute.
The XML schema attributes elementFormDefault attribute and attributeFormDefault attribute control whether elements and attributes are qualified in a given schema. In Caché XML support, you use a class parameter to specify whether elements are qualified.
An XML schema is a valid XML document, making it easier to develop tools that operate on schemas.
An XML schema can specify a richer set of features and includes type information for values.
Formally, a schema document is a XML document that complies with the W3 XML Schema specification (https://www.w3.org/XML/Schema). It obeys the rules of XML and uses some additional syntax. Typically the extension of the file is .xsd.
<SampleElement> sample text node </SampleElement>
Types are either simple or complex.
Each attribute has a simple type. Simple types also represent elements that have no attributes and no child elements (only text nodes). Complex types represent other elements.
The following fragment of a schema shows some type definitions:
<s:complexType name="Person"> <s:sequence> <s:element name="Name" type="s:string" minOccurs="0" /> <s:element name="DOB" type="s:date" minOccurs="0" /> <s:element name="Address" type="s_Address" minOccurs="0" /> </s:sequence> <s:attribute name="GroupID" type="s:string" /> </s:complexType> <s:complexType name="s_Address"> <s:sequence> <s:element name="City" type="s:string" minOccurs="0" /> <s:element name="Zip" type="s:string" minOccurs="0" /> </s:sequence> </s:complexType>
<?xml version="1.0" encoding="UTF-8"?>