tags:

views:

91

answers:

1

Hi all:

I am working on a C# application that involves using XML schema file as databases for message definitions and XML file as databases for message data.

I was following the example I found:http://msdn.microsoft.com/en-us/library/system.xml.xmldatadocument.dataset%28v=VS.100%29.aspx

I wrote my own xsd and XML file. I used the same approach in the example, read the xsd file and then load the xml file. But I don't have any "Rows" created for my DataTable. I used debugger to step through my codes. When I am get my DataTable use xmlDataDocument.DataSet.Tables["name of the table"], the Rows property of that tables is 0.

Does anybody know what might cause the DataSet tables not get populated after I loaded the xmlDataDocument with XML file?

Here is a fragment of XSD file:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="test"
    targetNamespace="http://tempuri.org/test.xsd"
      elementFormDefault="qualified"
    xmlns="http://tempuri.org/test.xsd"
    xmlns:mstns="http://tempuri.org/test.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

<xs:element name="reboot_msg">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="header_s">
          <xs:sequence>

           <xs:element name="que_name">
            <xs:simpleType>
             <xs:restriction base="xs:string">
              <xs:minLength value="4"/>
               <xs:maxLength value="8"/>
              </xs:restriction>
             </xs:simpleType>
            </xs:element>

        <xs:element name="priority" type="xs:unsignedShort"/>

          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>

and here is a fragment of the XML file:

<?xml version="1.0" standalone="yes"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

  <reboot_msg>
    <message_length>16</message_length>
    <message_type>7</message_type>
    <message_sequence>0</message_sequence>
    <que_name>NONE</que_name>
    <priority>5</priority>
  </reboot_msg>

It could be the XML and XSD file I created missed something. Please help.

Thanks

A: 

To use an XML Schema with XmlDataDocument, you should only create the schema in the DataSet Designer. XmlDataDocument, and DataSet in general, can only handle a subset of XML Schema. To ensure that your schema only uses that subset, you should create it using the DataSet Designer.

John Saunders
John, thanks for the answer. Can you point me to a document that explains this more? What do you mean a subset of XML schema. I created the xsd file by adding a new xsd file in my project using visual studio 2008.
alex
@alex: I doubt there's a document - `XmlDataDocument` is even deprecated as of .NET 4.0. As one class of example, consider that the DataSet Designer will only produce an XSD that can map to the relational structures used by a DataSet. That implies no `xs:choice`, no type used as a "child" type by more than one "parent" type, etc. These are perfectly valid XML Schema features that cannot be used by a DataSet.
John Saunders
I figured it out. Instead of using xmlDataDocument.load() function to load the xml file, I used XmlDataDoc.DataSet.ReadXml(xml_file_name, XmlReadMode.InferSchema). Now I can see new Row created for the tables in the Dataset.
alex