April 16, 2004

How is the mapping from xsd to DataSet done?

I am trying to rewrite DataSet.ReadXmlSchema(). There had been great prior art named XmlSchemaMapper by Ville Palo, but since at the time he wrote up that class, there was no complete XML Schema stack, so he had to have a hard time to implement it without Post Schema Compilation Information. So I thought it is time to improve them and simplify the class. Actually, I'm on creating another class.

I began with the analysis of ReadXmlSchema() behavior. Actually, Microsoft had written Generating DataSet Relational Structure from XML Schema (XSD), a detailed documentation about DataSet and XML interoperability. So you will be content with that doc. Here is another attempt to describe "how are XML schemas consumed by ReadXmlSchema()". I will implement the class based on ths analysis. Comments are applicable.

Targetable Schema Components

Only global global elements that hold complex type are converted into a table. The components of the type of the element are subsequently converted into a table, BUT there is an exception. As for "DataSet elements", the type is just ignored (see "DataSet Element definition" below).

Unused complex types will never be converted.

Global simple types and global attributes are never converted. They cannot be a table. Local complex types are also converted into a table.

Local elements are converted into either a table or a column in the "context DataTable".

Name Convention (incomplete)

Since local complex types are anonymous, we have to name for each component. Thus, and since complex types and elements can have the same name each other, we have to manage a table for mappings from a name to a component. The names must be also used in DataRelation definitions correctly.

DataSet element definition

"DataSet element" is such element that has an attribute msdata:IsDataSet (where prefix "msdata" is bound to urn:schemas-microsoft-com:xml-msdata).

Only the first global element that matches the condition above is regarded as DataSet element (by necessary design or just a bug?) instead of handling as an error.

All global elements are considered as an alternative in the dataset element.

For local elements, msdata:IsDataSet are just ignored.

Importing Complex Types

When an xs:element is going to be mapped, its complex type (remember that only complex-typed elements are targettable) are expanded to DataColumn.

DataColumn has a property MappingType that shows whether this column came from attribute or element.

[Question: How about MappingType.Simple? How is it used?]

Additionally, for particle elements, it might also create another DataTable (but for the particle elements in context DataTable, it will create an index to the new table).

For group base particles (XmlSchemaGroupBase; sequence, choice, all) each component in those groups are mapped to a column. Even if you import "choice" or "all" components, DataSet.WriteXmlSchema() will output them just as a "sequence".

Identity Constraints and DataRelations

Only constraints on "DataSet element" is considered. All other constraint definitions are ignored. Note that it is DataSet that has the property Relations (of type DataRelationCollection).

xs:key and xs:unique are handled as the same (then both will be serialized as xs:unique).

The XPath expressions in the constraints are strictly limited; they are expected to be expandable enough to be mappable for each

  • selector to "any_valid_XPath/is/OK/blah" where "blah" is one of the DataTable name. It looks that only the last QName section is significant and any heading XPath step is OK (even if the mapped node does not exist).

  • field to QName that is mapped to DataColumn in the DataTable (even ./QName is not allowed)

Posted by atsushi at April 16, 2004 06:42 PM
Comments

Nice site. Keep up the good work. Bryian

Posted by: buy phentermine on June 8, 2004 04:11 AM
Post a comment