Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous section

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.

Copy code to clipboard

Attributes reside within elements, as shown below, and an element can have any number of attributes.

<Patient ID="QD5690">Cromley,Marcia N.</Patient>
Copy code to clipboard
CDATA section
Non-validated data goes here.  
You can even have stray "<" or ">" symbols in it. 
Copy code to clipboard

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-->
Copy code to clipboard
content model
  • 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.

default namespace
<Person xmlns="">
  <Name>Isaacs,Rob G.</Name>
Copy code to clipboard

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="">
  <s01:Name>Isaacs,Rob G.</s01:Name>
Copy code to clipboard
DTD (document type definition)
<Patient>Cromley,Marcia N.</Patient>
Copy code to clipboard

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:


Copy code to clipboard

In practice, elements are likely to refer to different parts of data records, such as:

<Student level="undergraduate">
Copy code to clipboard
Copy code to clipboard
global element

Attributes are global or local in the same way.

local element

You include a namespace declaration with one of the following syntaxes:

Copy code to clipboard

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="">
   <Name>Ravazzolo,Roberta X.</Name>
Copy code to clipboard

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.

processing instructions (PI)
<?xml-stylesheet type="text/css" href="mystyles.css"?>
Copy code to clipboard
root, root element, document element
<?xml version="1.0" encoding="UTF-8"?>
   <s01:Person xmlns:s01="" GroupID="J1151">
      <Name>Frost,Sally O.</Name>
Copy code to clipboard

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"?>
   <Person xmlns="" GroupID="J1151">
      <Name>Frost,Sally O.</Name>
Copy code to clipboard

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 ( It obeys the rules of XML and uses some additional syntax. Typically the extension of the file is .xsd.

style sheet
text node
sample text node
Copy code to clipboard

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: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:attribute name="GroupID" type="s:string" />
<s:complexType name="s_Address">
        <s:element name="City" type="s:string" minOccurs="0" />
        <s:element name="Zip" type="s:string" minOccurs="0" />
Copy code to clipboard
well-formed XML
XML declaration
<?xml version="1.0" encoding="UTF-8"?>
Copy code to clipboard