I have a strongly typed dataset whose schema looks as such:
<?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="cc">
<xs:complexType>
<xs:sequence>
<xs:element name="usr" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="distributionList"
nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="nam" type="xs:string"
form="unqualified" />
<xs:attribute name="uid" type="xs:string"
form="unqualified" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
I have a test function in a windows form in which I try to fill the
dataset up with xml. My function looks as such:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New Dataset1
Dim xreader As XmlReader
Try
Dim stream As New System.IO.StringReader("<cc>" & _
"<usr uid=""123"" nam=""Test User"">" & _
"<distributionList>testing</distributionList>" & _
"</usr>" & _
"</cc>")
xreader = New XmlTextReader(stream)
' I am crashing here
ds.ReadXml(xreader, XmlReadMode.InferSchema)
MsgBox(ds.GetXml)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
My believe my problem lies in the schema. If I specify multiple or
zero distributionList nodes the xml is read into the dataset
correctly. If I specify just one distributionList node I get a
"Specified cast is not valid". Am I missing something in the schema?
Thanks,
Collin