Sapphire Developer Guide

Sapphire XML Binding

Full content pending...

Default XML Binding

There are cases when it is convenient to be able to take a model or a part of a model and serialize it as XML without spending time specifying detailed binding. This comes up, for instance, when debugging or writing unit tests. To address this requirement, Sapphire supports default XML binding that doesn't require any XML binding annotations to be used.

Default XML binding uses property and type names for element names in XML. More formally:

  1. A model element is mapped to an XML element whose name is derived from model element type. The local type name is used (no package prefix) and the 'I' prefix is removed.
  2. A property is mapped to an XML element whose name is equal to the property name.
  3. The value of a value property is stored as text content inside the property's XML element.

Here is a small example of what default XML binding would produce for the Sapphire contacts sample if that sample didn't specify XML binding via explicit annotations:

<ContactRepository>
  <Contacts>
    <Contact>
      <Name>John</Name>
      <PhoneNumbers>
        <PhoneNumber>
          <Type>home</Type>
          <AreaCode>555</AreaCode>
          <LocalNumber>555-5555</LocalNumber>
        </PhoneNumber>
        <PhoneNumber>
          <Type>mobile</Type>
          <AreaCode>555</AreaCode>
          <LocalNumber>555-6666</LocalNumber>
        </PhoneNumber>
      </PhoneNumbers>
    </Contact>
    <Contact>
      <Name>Beth</Name>
    </Contact>
  </Contacts>
</ContactRepository>