Special Topics
This topic describes additional special topics.
The XML examples in this topic are in literal format.
Class and Property Parameters Discussed on This Page |
---|
|
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® data platform recognizes these forms as equivalent. When you export objects with %XML.WriterOpens in a new tab, you can control the closing form, but not by modifying the XML projection itself. See Controlling the Closing of Elements.
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.IdOpens in a new tab (for the internal ID), %XML.OidOpens in a new tab (for the OID), and %XML.GUIDOpens in a new tab (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.IdOpens in a new tab, %XML.OidOpens in a new tab, or %XML.GUIDOpens in a new tab. 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
(XMLNAME="IRISID", XMLPROJECTION="ELEMENT") [Private, Transient];
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"?>
<Root>
<Person>
<IRISID>1</IRISID>
<Name>Marks,Jules F.</Name>
<DOB>1989-04-02</DOB>
</Person>
<Person>
<IRISID>2</IRISID>
<Name>Palmer,Angelo O.</Name>
<DOB>1937-11-15</DOB>
</Person>
...
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.