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.

attribute
ID="QD5690"
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
<myelementname><![CDATA[ 
Non-validated data goes here.  
You can even have stray "<" or ">" symbols in it. 
]]></myelementname>
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.

comment
<!--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="http://www.person.org">
  <Name>Isaacs,Rob G.</Name>
  <DOB>1981-01-29</DOB>
</Person>
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="http://www.person.org">
  <s01:Name>Isaacs,Rob G.</s01:Name>
  <s01:DOB>1981-01-29</s01:DOB>
</s01:Person>
Copy code to clipboard
DOM
DTD (document type definition)
element
<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:

<EndDate></EndDate>

<EndDate/>
Copy code to clipboard

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>
Copy code to clipboard
entity
&characters;
Copy code to clipboard
global element

Attributes are global or local in the same way.

local element
namespace

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

xmlns="your_namespace_here"
pre:xmlns="your_namespace_here"
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="http://www.person.com">
   <Name>Ravazzolo,Roberta X.</Name>
   <DOB>1943-10-24</DOB>
</s01:Person>
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
prolog
root, root element, document element
qualified
<?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>
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"?>
<Root>
   <Person xmlns="http://www.person.com" GroupID="J1151">
      <Name>Frost,Sally O.</Name>
      <DOB>1957-03-11</DOB>
   </Person>
</Root>
Copy code to clipboard

In this case, the <Person> element defines a default namespace, which applies to the child elements and the attribute.

Note:

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.

schema
  • 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.

style sheet
text node
<SampleElement>
sample text node
</SampleElement>
Copy code to clipboard
type

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>
Copy code to clipboard
unqualified
well-formed XML
XML declaration
<?xml version="1.0" encoding="UTF-8"?>
Copy code to clipboard
XPath
XSLT