开发者

myXmlDataDoc.DataSet.ReadXml problem

I am using

myXmlDataDoc.DataSet.ReadXml(xml_file_name, XmlReadMode.InferSchema);

to populate the tables within the dataset created by reading in a xml schema using:

myStreamReader = new StreamReader(xsd_file_name);
myXmlDataDoc.DataSet.ReadXmlSchema(myStreamReader);

The problems I am facing is when it comes to read the xml tag:

<xs:element name="parameters" minOccurs="0" maxOccurs="12" type="xs:unsignedInt"/>

The readXml function puts the element in a different table and everything in the tables are 0s. Here is the print out of the datatable:

TableName: test_data
 100     2   1  
TableName: parameters
 1   0
 2   0
 3   0
 4   0
 5   0
 6   0
 7   0
 8   0
 9   0
 10  0
 11  0
 12  0

In my xsd file, I represent an array using this:

<xs:element name="test_data">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="test_base">
                <xs:sequence>
                    <xs:element name="a" type="xs:unsignedShort"/>
                    <xs:element name="b" type="xs:unsignedShort"/>开发者_开发技巧;
                    <xs:element name="c" type="xs:unsignedInt"/>
                    <xs:element name="parameters" minOccurs="0" maxOccurs="12" type="xs:unsignedInt"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:element>

And here is my xml file:

<test_data>
    <a>100</a>
    <b>2</b>
    <c>1</c>
    <parameters>1</parameters>
    <parameters>2</parameters>
    <parameters>3</parameters>
    <parameters>4</parameters>
    <parameters>5</parameters>
    <parameters>6</parameters>
    <parameters>7</parameters>
    <parameters>8</parameters>
    <parameters>9</parameters>
    <parameters>10</parameters>
    <parameters>11</parameters>
    <parameters>12</parameters>
</test_data>

I am expecting after the readXml function call, the "parameters" is part of the test_data table.

TableName: test_data
 100     2   1  1   2  3  4  5  6  7  8  9  10  11  12

Does anyone knows what's wrong?


Using a DataSet limits you to XML Schemas that map to the relational model. This will sometimes not be what you expect.

I recommend that you create a DataSet, either manually, or with the DataSet Designer in Visual Studio, that you believe most closely matches the data you're working with. Then either look at the resulting XSD or use DataSet.WriteXmlSchema to write the schema to a file. Look at the file - that's the XML schema you should use.

I don't think you'll get it to accept complexContent or even extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜