Introduction to Object-XML Projections
This book describes how to project InterSystems IRIS objects to XML and how to control that projection to XML elements, attributes, and types.
This chapter introduces how to project objects to XML and explains why you might want to do this.
For information on XML standards supported in InterSystems IRIS, see “Standards Supported by InterSystems IRIS” in Using XML Tools.
The phrase projecting an object to XML means defining how that object can be used as an XML document. To project an object to XML, you add %XML.AdaptorOpens in a new window to the superclass list of the class that defines the object, as well as any other object classes used by that class, with minor exceptions.
This activity is also called defining the XML projection of the class that defines the object or XML-enabling that class.
How It Works
When you define the XML projection for a class:
The system generates additional INT code for the class that enables you to use class instances as XML documents. (This code is generated when you compile the class, and you should not edit it.)
Each property of your class automatically inherits from %XML.PropertyParametersOpens in a new window.
%XML.AdaptorOpens in a new window adds XML-related class parameters to your class.
%XML.PropertyParametersOpens in a new window adds XML-related property parameters to properties in your class.
Data type properties define the LogicalToXSD() and XSDToLogical() methods, which control how data is transformed when output to XML or input from XML.
Then, if the default projection is not suitable for your needs, you edit the XML-related parameters in your class as needed.
The XML projection for a given class determines how instances of that class correspond to XML documents and vice versa. For example:
You can control the XML projection in many ways, including the following:
Controlling the structure to which a property is projected. For example, simple properties can be projected as either elements or attributes — or they cannot be projected at all, as shown in the preceding example.
Controlling the XML element and attribute names.
Controlling the XML namespaces to which elements and attributes are assigned.
Controlling the details of how the InterSystems IRIS class is mapped to an XML schema.
Most of these parameters affect all the scenarios in which you use the XML-enabled class. A few parameters apply in certain scenarios; this book notes these exceptions.
Possible Applications for XML Documents
You can use XML documents in a variety of practical applications, including:
As a standard format in messaging applications. This includes industry-standard protocols as well as homegrown solutions.
As a standard format for data exchange between applications and users.
As a standard representation for external data storage. This may include traditional database records or it may include more complex content such as documentation.
As the payload of SOAP messages sent between web services and web clients.
As the contents of an XData block in a class definition. See “XData Blocks” in Defining and Using Classes.