Hi,
I've looked all over for any information about this, and either this is
a bug that I cannot find reported or I've misunderstood something.
Lets say, in the XML Designer in VS.NET 2003, you drag over an element
(call it MyElement) and add another element of type string (call it
NormalElement) as a member. If you look at the generated typed Dataset
code there should be just one table ("MyElementDataTable"), with one
column (NormalElement).
If you set maxOccurs to something greater than 1, or unbounded, then
the dataset has to contain an additional table to allow for more than 1
NormalElement in MyElement. It will call this "NormalElementDataTable".
There will be a relation between MyElementDataTable and
NormalElementDataTable. (You can see all this easier in the "preview
Dataset", which you can access when you right click on the designer
surface).
So far, so good. If, however, you try to change the type of
NormalElement to use a Simple Type, either unnamed or named, and look
at the generated dataset, the NormalElementDataTable has disappeared.
The dataset now only allows 1 NormalElement per MyElement, although I
may have specified 10 or unbounded or whatever!
If I use XSD.exe /c, then the classes generated, whether NormalElement
uses a simple type or built-in one like string, seem to be correct
(i.e. NormalElement will be an array in MyElement).
Here is an example of the schema I mean:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Dataset1"
targetNamespace="http://tempuri.org/Dataset1.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/Dataset1.xsd"
xmlns:mstns="http://tempuri.org/Dataset1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Dataset1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="MyElement">
<xs:complexType>
<xs:sequence>
<xs:element name="NormalElement" minOccurs="0" maxOccurs="10">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="7" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Can anyone confirm whether or not this is a bug, or expected behaviour
(and if so, why). Perhaps I have misunderstood the maxoccurs occurrence
attribute?
Cheers,
Pete Beech