This book describes how to project Caché 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.
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.
When you define the XML projection for a class:
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 Caché 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.
When you define the XML projection for a class, you have access to a large set of Caché tools, which are suitable for many practical applications. You can use these tools to work with your class in any of the following ways:
Export objects of that class to XML documents.
Import XML documents into Caché, which creates new instances of that class, which you can then save.
Use objects of that class as arguments for web services and web clients.
Generate XML schemas. Caché implicitly defines an XML type for the class and uses that for validation when using objects of that class in any of the preceding ways.
Caché provides additional tools for working with XML documents, including arbitrary XML documents that do not correspond to Caché classes. These tools include support for DOM, XPath, and XSLT.
Caché uses the Caché SAX Parser to validate and parse inbound and outbound XML documents (SAX means Simple API for XML
). The Caché SAX Parser is a built-in SAX XML validating parser using the standard Xerces library. Caché SAX communicates with a Caché process using a high-performance, in-process call-in mechanism. You can fine-tune the parser or provide your own custom SAX interface classes.
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.