16.1.6. Recommendations on XML schema appearance


<< Prev   Next >>

In general, the XMLSchemaSet à XDTOFactory à XMLSchemaSet conversion does not result in an XML schema set that is similar to the source one. However, following recommendations on the XML schema appearance will ensure equivalence of the source set and the resulting set. Particularly:

  • For the XMLSchemaSet XDTOFactory XMLSchemaSet conversion, the resulting schema set will be similar to the source one.
  • Successful verification of properties of the XDTODataObject object, performed by the Validate() method, ensures that the object presentation in XML will correspond to the XML schema.
  • The maximum flexibility and no distortion when using the polymorphism is ensured.

The XML schema based on the XDTO factory with types, for which the values of the default parameters responsible for XML presentation of data, of course, corresponds to the recommendation above.

In general, recommendations below are the set of rules that ensure the best result from different perspectives.

XML schema cannot contain anonymous types

Constructions of the following type are not allowed:

<element name="Person">
<complexType>
<sequence>
<element name="FirstName" type="string" />
<element name="FamilyName" type="string" />
</sequence>
</complexType>
</element>

This fragment must look as follows:

<element name="Person" type="tns:PersonType">
<complexType name="PersonType">
<sequence>
<element name="FirstName" type="string" />
<element name="FamilyName" type="string" />
</sequence>
</complexType>
</element>

To model the complex types content (complexType), use the single sequence block without predefined values for minOccurs and maxOccurs attributes by default.

<complexType name="PersonType">
<sequence>
<element name="FirstName" type="string" />
<element name="FamilyName" type="string" />
</sequence>
</complexType>

With the all model, the source and resulting schemas are similar during the XMLSchemaSet à XDTOFactory à XMLSchemaSet conversion. However, this model has a number of restrictions. In particular, the maxOccurs attribute value for items in the all model cannot be greater than 1.

The choice model breaches the equivalence of the source and resulting schemas and does not allow the Validate() method to check whether the object data filling corresponds to the XML schema.

For the same reason, do not use several content models and do not set the minOccurs and maxOccurs attributes to custom values for sequence within a single complex type.

Present object properties as elements in XML

Presenting properties as XML attributes does not affect the equivalence of source and resulting schemas. However, there are some restrictions:

  • Values of object type cannot be presented in the attribute. Only value type values are allowed.
  • Properties with multiple values cannot be presented in the attribute.
  • In case of polymorphous types, the value type of property presented as the XML attribute can be corrupted. When a value is assigned to the property, the value type is aligned with the property type as you can specify the xsi:type attribute only for a property value in an XML element. The xsi:type attribute allows you to specify the property value type precisely.

As a result, you do not have to use simpleContent for complexType. This value saving model implies using attribute properties and the text that includes XML element.

It is not recommended to use the same names to declare an attribute and an element.

Do not use the mixed content model

Using construction similar to the one below in XML schema means that in the XML element that corresponds to the described type the text can be mixed with the XML elements.

<complexType name="FormLetter" mixed="true">

</complexType>

To support such information content of the XDTOObjectType object, the values of Sequential and Mixed properties are True, and XDTO sequence (XDTOSequence object) appears for each instance of this XDTODataObject object. Managing information content of such objects is much more complex then content of objects with the state presented by the set of properties only.

In most cases, there is no need to use mixed content.

The ElementFormDefault property of the XML schema must be set to Qualified.

This recommendation is the part of good style and XDTO maintains this style.

<< Prev   Next >>

Icon/Social/001 Icon/Social/006 Icon/Social/005 Icon/Social/004 Icon/Social/002