Skip to main content
Previous section   Next section

Introduction to Object-XML Projections

This book describes how to project Caché objects to XML and how to control that projection to XML elements, attributes, and types.

This topic introduces how to project objects to XML and explains why you might want to do this.

For information on XML standards supported in Caché, see “Standards Supported by Caché” in Using Caché XML Tools.

The Basics

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.Adaptor 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.PropertyParameters.

  • %XML.Adaptor adds XML-related class parameters to your class.

  • %XML.PropertyParameters 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.

Projection Options

The XML projection for a given class determines how instances of that class correspond to XML documents and vice versa. For example:

images/gxmlproj_xmlobj.png

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 Caché class is mapped to an XML schema.

With noted exceptions, these parameters affect all the scenarios in which you use the XML-enabled class.

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 Using Caché Objects.