Skip to main content

Special Topics

This chapter describes additional special topics.

The XML examples in this chapter are in literal format.

Class and Property Parameters Discussed in This Chapter

Controlling the Closing of Elements

In XML, an element that contains only attributes can be represented in either of the following ways:

<tag attribute="value" attribute="value" attribute="value"></tag>
<tag attribute="value" attribute="value" attribute="value"/>

InterSystems IRIS recognizes these forms as equivalent. When you export objects with %XML.Writer, you can control the closing form, but not by modifying the XML projection itself. See “Controlling the Closing of Elements” in the chapter “Writing XML Output from Objects” in Using XML Tools.

Handling a Document with Multiple Tags with the Same Name

A given element in XML can contain multiple elements that have the same name; these elements are distinguished from each other by their order. For example, the following is a legitimate XML document:

<?xml version="1.0" encoding="UTF-8"?>
      <Name>Able, Andrew</Name>
         <Street>6218 Clinton Drive</Street>
         <Street>110 High Street</Street>

It is slightly tricky to map such a document to an InterSystems IRIS class, because each class property must have a unique name.

To map such a document to an InterSystems IRIS class, do the following:

  • Set the XMLNAME property parameter as needed to map different class properties to the same XML name.

  • Set the XMLSEQUENCE class parameter equal to 1. As a precaution, this ensures that the mapping respects the order of the properties as listed in the class definition.

  • Make sure that the properties are listed in the class definition in the same order as in the XML document.

For example, consider the following class definition:

Class GXML.TestSequence.Person Extends (%Persistent, %XML.Adaptor)

Property Name As %Name [ Required ];
Property DOB As %Date(FORMAT = 5, MAXVAL = "+$h") [ Required ];
Property HomeAddress As GXML.TestSequence.Address(XMLNAME = "Address");
Property WorkAddress As GXML.TestSequence.Address(XMLNAME = "Address");

/// If the XMLSEQUENCE = 1, then the order of the XML elements must match the 
/// order of the class properties.  This allows us to deal with XML where the 
/// same field appears multiple times and is distinguished by the order.
Parameter XMLSEQUENCE = 1;


This class definition maps to the XML document shown previously.


If XMLSEQUENCE is 1, the XMLIGNOREINVALIDTAG parameter is ignored.

Controlling Unswizzling After Export

When you use InterSystems IRIS XML tools to export a persistent XML-enabled object, the system automatically swizzles all needed information into memory as usual; this information includes object-valued properties. After exporting the object, InterSystems IRIS unswizzles any lists of objects but does not (by default) unswizzle single object references. In the case of large objects, this can result in <STORE> errors.

To cause any single object references to be unswizzled in this scenario, set the XMLUNSWIZZLE parameter in your XML-enabled class as follows:

Parameter XMLUNSWIZZLE = 1;

The default for this parameter is 0.

Projecting InterSystems IRIS IDs for Export

When you project an InterSystems IRIS object at the top level (rather than as a property of another object), its internal ID, OID, and globally unique ID are not available as object properties, and these IDs are thus are not projected. However, in some cases, you might want to use an object ID as the unique identifier. Then, for example, you can match an incoming (changed) object to the corresponding stored object, before updating the stored object.

InterSystems IRIS XML support provides several helper classes that you can use to project InterSystems IRIS object identifiers to XML documents: %XML.Id (for the internal ID), %XML.Oid (for the OID), and %XML.GUID (for the globally unique ID).

To use these classes, add a special property to your XML-enabled class whose purpose is to contain the ID that you will export. The property must be of type %XML.Id, %XML.Oid, or %XML.GUID. Make sure that this property is projected, and mark it as transient so that it is not included in the SQL projection of the class.

When you are exporting to XML, you bring an object of your XML-enabled class into memory. When the object is in memory, the special property you added retrieves the requested ID from InterSystems IRIS internal storage and contains that value (so that you can export it).

For example, consider the following class:

Class MyApp4.Obj.Person4 Extends (%Persistent,%Populate,%XML.Adaptor) 

Property IdForExport As %XML.Id 

Property Name As %Name;

Property DOB As %Date(FORMAT = 5, MAXVAL = "+$h");


In this class, the special property is IdForExport. This property is specifically projected with the XML element name of IRISID.

Example output for this class is as follows:

<?xml version="1.0" encoding="UTF-8"?>
      <Name>Marks,Jules F.</Name>
      <Name>Palmer,Angelo O.</Name>

Controlling the Namespace Prefix on Export

When you generate XML output for an object, the system generates namespace prefixes as needed, but you can specify the prefixes if needed. To do so, set the following parameter in the class definitions for the XML-enabled objects:


Specifies the prefix to associate with the namespace for this class.

For details, see “Writing XML Output from Objects,” in Using XML Tools.

Handling Unexpected Elements and Attributes on Import

Because the source XML documents might contain unexpected elements and attributes, your XML-enabled classes provide two parameters to specify how to react when you import such a document. For example, consider the following class definition:

Class GXML.TestImportParms.Person Extends (%Persistent,%XML.Adaptor) 

Property Name As %Name [ Required ];
Property DOB As %Date(FORMAT = 5, MAXVAL = "+$h") [ Required ];

Also consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <Person employeeID="450">
      <Name>Dillard, Daniel</Name>
         <Street>810 Main Street</Street>

The employeeID attribute and the <Address> element do not correspond to properties in the class and are therefore unexpected.

To specify how to handle unexpected attributes and elements, use the following parameters of your XML-enabled classes:


Controls how to handle attributes that are unexpected. If this parameter is 1 (the default), such attributes are ignored. If it is 0, they are treated as errors, and import fails.


Controls how to handle elements that are unexpected. If this parameter is 1, such elements are ignored. If it is 0 (the default), they are treated as errors, and import fails.

These parameters affect only import.


The xmlns attribute, array key name attribute, and schema instance (xsi) attribute are always ignored.

Also, if XMLSEQUENCE is 1, the XMLIGNOREINVALIDTAG parameter is ignored. See the section “Handling a Document with Multiple Tags with the Same Name,” earlier in this chapter.