You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Syntax
set aBlob = anObject.classToXMLFragment()
set aBlob = anObject.classToXMLFragment(options)
Semantics

The operation takes any object (anObject) and tries to map it to an XML fragment. The fragment structure is given by the class definition of anObject. If this is not possible an error is raised (e.g. XML parser errors, invalid mappings, etc.)

By default the following mapping rules apply:

  • Class attributes are mapped to XML attributes.
  • Association ends are mapped to XML elements.

These default rules can be overridden by using the stereotypes XMLElementXMLAttribute, and XMLCharacters on  class properties.
More about these mapping rules, stereotypes and tagged values (e.g. for number and date & time formatting) can be found on Controlling the XML Serialization With Stereotypes.

A conversion with operation classToXMLFragment() always returns an object of type Blob. To display this data as a String you need to transcode it first (see transcodeToString() Operation).

SubstitutablesanObjectTarget object, can be any complex object. However, simple types and arrays are not supported, since they do not map naturally to a well formed XML document.
options MultiExcerpt named classToXML_options was not found -- Please check the page name and MultiExcerpt name used in the MultiExcerpt-Include macro
Examples
set xmlBlob = myAddress.classToXMLFragment();

XML Serialization Example

Assume you have an object myAddress of type Address.

The following action script serializes this object.

set xmlBlob = myAddress.classToXMLFragment();

The sample XML fragment below illustrates the mapping executed by classToXMLFragment(). The object myAddress of type Address (see class diagram) is mapped the depicted XML fragment:

<name>ACME Corp.</name>
<street>108, Kearny Avenue</street>
<town>Newark</town>
  • No labels