BUG: Validating datasets written from a generated strong-typed dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Ernst

    BUG: Validating datasets written from a generated strong-typed dataset

    I have a pretty simple XSD schema:

    *************** *************** **************
    * XSD SCHEMA
    *************** *************** **************
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema id="PageHitStat istics"
    targetNamespace ="urn:PageHitSt atistics"
    elementFormDefa ult="qualified"
    xmlns="urn:Page HitStatistics"

    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexTy pe name="CounterDe f">
    <xs:attribute name="count"
    type="xs:nonNeg ativeInteger" use="required" />
    <xs:attribute name="page" type="xs:string "
    use="required" />
    </xs:complexType>

    <xs:element name="PageCount ers">
    <xs:complexType >
    <xs:choice minOccurs="0"
    maxOccurs="unbo unded">
    <xs:element name="counter"
    type="CounterDe f" minOccurs="0" maxOccurs="unbo unded" />
    </xs:choice>
    <xs:attribute type="xs:dateTi me"
    name="CreateDat eTime" />
    </xs:complexType>
    </xs:element>
    </xs:schema>
    *************** *************** **************
    * END XSD SCHEMA
    *************** *************** **************


    Now, I've generated a strongly typed dataset from the XSD
    using the MSDataSetGenera tor tool through VS.Net 2003.

    When I write the XML using the WriteXml method of the
    dataset, it writes XML that will not validate with the
    schema it was generated from. The cause of the problem is
    the "CreateDateTime " attribute of the "PageCounte rs"
    element. If this attribute is ommitted, the generated
    dataset writes valid xml, like:

    <PageCounters >
    <counter count="2" page="/default.aspx" />
    </PageCounters>

    With the "CreateDateTime " attribute, it writes:
    <PageHitStatist ics>
    <PageCounters CreateDateTime= "2003-12-10T15:10:17.524 8400-
    06:00">
    <counter count="1"
    page="/dbaweb/internalweb/viewstats.aspx" />
    <counter count="1"
    page="/dbaweb/reports/dbvendorcase.as px" />
    <counter count="1"
    page="/dbaweb/reports/dbrepairs.aspx" />
    <counter count="2" page="/dbaweb/default.aspx" />
    </PageCounters>
    </PageHitStatisti cs>

    This XML fails to validate because
    the "PageHistStatis tics" element is not declared. Does
    the dataset generator have a limitation that the root node
    cannot have any attributes? Is this documented somewhere,
    or is this a bug (which is the assumption underwhich I'm
    working now).

    I am able to work around this be adding a new root
    element, "PageHitStatist ics", with no attributes and then
    setting the MaxOccurs of the "PageCounte rs" to 1.

    This seems to be a big problem because although the
    DataSet can read the correct xml, it writes invalid xml
    (according to the schema), and then it cannot read an xml
    file it has written (huge problem).

    Thanks,
    Nathan Ernst
    nREMOVEathan.er ALLnst@nav-inCAPSternation al.com
    Remove all capital letters from address to reply.
Working...