Bug in MsDataSetGenerator when using empty typed elements?

Hi,

Take the following XML file:

< xml version="1.0" encoding="utf-8" >
<
root>
    <
object name="foo">bar</object>
    <
object name="bar" />
</
root>

Now use the "Create Schema" command from the VS.NET 2005 IDE.  This creates the following (valid) schema:

< xml version="1.0" encoding="utf-8" >
<
xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <
xs:element name="root">
    <
xs:complexType>
      <
xs:sequence>
        <
xs:element maxOccurs="unbounded" name="object">
          <
xs:complexType>
            <
xs:simpleContent>
              <
xs:extension base="xs:string">
                <
xs:attribute name="name" type="xs:string" use="required" />
              </
xs:extension>
            </
xs:simpleContent>
          </
xs:complexType>
        </
xs:element>
      </
xs:sequence>
    </
xs:complexType>
  </
xs:element>
</
xs:schema>

Now set the CustomTool property on the XSD file to "MsDataSetGenerator".  And try using the dataset in your project.  Something like:

Dim x As New root
x.ReadXml(
"test.xml")

This will throw a ConstraintException on the 2nd "object" element.  Assigning any value to the element will work as long as it is not empty.  Even though the XML validates against the XSD schema (a string can be empty).  Even when I tried extending from a custom type with min-length explicitly set to 0, the dataset will still fail to validate.

Is this a bug or am I doing something wrong here   Is there a workaround without having to modify XML files

Cheers,
     Thomas



Answer this question

Bug in MsDataSetGenerator when using empty typed elements?

  • stevenhu

    Yes, I see now. When I loaded this up into the DataSet designer it showed the object_text column as "AllowDBNull=false", so I toggled this to "true" and then it worked. It also changed the schema to the following:

    <xs:element name="root">

    <xs:complexType>

    <xs:choice minOccurs="0" maxOccurs="unbounded">

    <xs:element name="object" nillable="true" >

    <xs:complexType>

    <xs:simpleContent >

    <xs:extension base="xs:string">

    <xs:attribute name="name" type="xs:string" use="required" />

    </xs:extension>

    </xs:simpleContent>

    </xs:complexType>

    </xs:element>

    </xs:choice>

    </xs:complexType>

    </xs:element>


  • MarkB.

    Did you try to use generated dataset to import the XML file It generates just fine for me too, but when I use it to import the XML file it throws a validation error.

    I've noticed that you refer to a generated C# file, I'm using VB.NET. Maybe that's the issue

    Thanks for the reply.
    Thomas


  • Sean Perkin

    I could not reproduce this error.  I followed your steps and it generated a the test.designer.cs file containing strongly typed dataset just fine.
  • TimRaml

    I can't believe nobody can help me out here :(

     


  • Bug in MsDataSetGenerator when using empty typed elements?