Home All Groups Group Topic Archive Search About

DataSet Xml Generation Does Not Honor Format of Supplied Schema

Author
24 Apr 2006 4:14 PM
Garrek
I'm having a problem in which the .Net 2.0 DataSet does not properly nest Xml
upon output when using a supplied schema.

I've created an Xml schema that I wish to push into a DataSet.  My code then
pushes data into this DataSet (not from a Database).  Finally, I want to use
the DataSet.GetXml() method to supply the data in the structure as defined by
my schema.

My understanding is that the Xml Schema standard allows us to define at the
root level a number of complexType entries which supply the structure of an
element.  I can then instantiate this such as follows:

<xs:complexType name="examType">
  <xs:all>
    <xs:element name="task"  type="taskType" />
  </xs:all>
  <xs:attribute name="examId" type="xs:positiveInteger" />
</xs:complexType>

<xs:element name="myRoot" />
  <xs:sequence>
    <xs:element name="exam" type="examType" />
  </xs:sequence>
</xs:element>

<xs:key name="ExamIdKey" msdata:PrimaryKey="true">
  <xs:selector xpath="exam" />
  <xs:field xpath="attribute::examId" />
</xs:key>
<xs:keyref name="TaskExam" refer="rav:ExamIdKey" msdata:IsNested="true">
  <xs:selector xpath="exam/task" />
  <xs:field xpath="attribute::parentExamId" />
</xs:keyref>


In this situation I should have a nested structure of Xml elements.  I've
also supplied the necessary <key> and <keyref> elements which the DataSet
should honor in defining the relationships between the tables.  Unfortunately
I'm finding that the DataSet still creates a new column for the task element
called 'task_id'.

I've now chnaged my schema so I do not define the complexType structures
such as pictured above.  I should be able to but I'm thinking this is a bug
in .Net 2.0.  I've now changed it so the definitions exist in the
hierarchical fashion, I'm not referencing complexType definitions.  You can
see the new schema below.

If anyone could PLEASE tell me if this is indeed a bug or what I'm doing
wrong.  I should be able to define the primary keys and relationships in the
Xml Schema as I've done above.  The DataSet.GetXml() should then use this
information to output the Xml in a hierarchical fashion as I need.  But it
doesn't.  



<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://myschemaURI"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:mysys="http://myschemaURI"
           xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

  <xs:simpleType name="taskClassSimpleType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="type1" />
      <xs:enumeration value="type2" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="statusSimpleType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="scored" />
      <xs:enumeration value="not-scored" />
      <xs:enumeration value="unknown" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="filenameSimpleType">
    <xs:restriction base="xs:string">
      <xs:minLength value="1" />
      <xs:maxLength value="255" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="taskPointsSimpleType">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0" />
      <xs:maxExclusive value="100" />
    </xs:restriction>
  </xs:simpleType>


  <xs:element name="statExam">
    <xs:complexType>
      <xs:all>
        <xs:element name="exam">
          <xs:complexType>
            <xs:all>
              <xs:element name="task" minOccurs="1">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="curriculumIndex" minOccurs="1">
                      <xs:complexType>
                        <xs:choice>
                          <xs:element name="locationIndex">
                            <xs:complexType>
                              <xs:attribute name="ver" type="xs:string"
use="required" />
                              <xs:attribute name="ch"
type="xs:positiveInteger" use="required" />
                              <xs:attribute name="o"
type="xs:positiveInteger" use="required" />
                              <xs:attribute name="pg"
type="xs:positiveInteger" use="required" />
                            </xs:complexType>

                          </xs:element>
                        </xs:choice>
                      </xs:complexType>

                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="sysTaskId" type="xs:positiveInteger"
use="required" />
                  <xs:attribute name="parentExamCountId"
type="xs:positiveInteger" use="required" />
                  <xs:attribute name="taskClass"
type="mysys:taskClassSimpleType" use="required" />
                  <xs:attribute name="status" type="mysys:statusSimpleType"
use="required" />
                  <xs:attribute name="graphicFilename"
type="mysys:filenameSimpleType" use="optional" />
                  <xs:attribute name="minPoints"
type="mysys:taskPointsSimpleType" use="required" />
                  <xs:attribute name="maxPoints"
type="mysys:taskPointsSimpleType" use="required" />
                </xs:complexType>

              </xs:element>
            </xs:all>
            <xs:attribute name="examCountId" type ="xs:positiveInteger"
use="required" />
            <xs:attribute name="acronym" type="xs:string" use="required" />
            <xs:attribute name="title" type="xs:string" use="required" />
            <xs:attribute name="date" type="xs:date" use="required" />
          </xs:complexType>

          <xs:key name="TaskIdKey" msdata:PrimaryKey="true">
            <xs:selector xpath="mysys:task" />
            <xs:field xpath="attribute::mysys:sysTaskId" />
          </xs:key>
          <xs:keyref name="TaskExam" refer="mysys:ExamIdKey"
msdata:IsNested="true">
            <xs:selector xpath="mysys:task" />
            <xs:field xpath="attribute::mysys:parentExamCountId" />
          </xs:keyref>
        </xs:element>
      </xs:all>
    </xs:complexType>
    <xs:key name="ExamIdKey" msdata:PrimaryKey="true">
      <xs:selector xpath="mysys:examType" />
      <xs:field xpath="attribute::mysys:examCountId" />
    </xs:key>
  </xs:element>

</xs:schema>

AddThis Social Bookmark Button