title: Is DataSet supports complex type when GetXml method?
body: <p>I have the schema below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
      &lt;xs:element name="WSParam"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="domain" type="xs:string"/&gt;
                  &lt;xs:element name="userName" type="xs:string"/&gt;
                  &lt;xs:element name="Cases"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:sequence&gt;
                              &lt;xs:element name="caseName" type="xs:string"/&gt;
                          &lt;/xs:sequence&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I expected the output of DataSet.GetXml() below:</p>
  
  <pre><code>&lt;NewDataSet&gt;
      &lt;WSParam&gt;
          &lt;domain&gt;ad&lt;/domain&gt;
          &lt;userName&gt;admin&lt;/userName&gt;
          &lt;Cases&gt;
              &lt;caseName&gt;case 1&lt;/caseName&gt;
          &lt;/Cases&gt;
      &lt;/WSParam&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>But the output is:</p>
  
  <pre><code>&lt;NewDataSet&gt;
      &lt;WSParam&gt;
          &lt;domain&gt;ad&lt;/domain&gt;
          &lt;userName&gt;admin&lt;/userName&gt;
      &lt;/WSParam&gt;
      &lt;Cases&gt;
          &lt;caseName&gt;case 1&lt;/caseName&gt;
      &lt;/Cases&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>Anyone confirm me the correct behavior of DataSet.GetXml() with complex type or I miss something.</p>
  
  <p>Any guidance is highly appreciated.</p>
  
  <p><strong>UPDATES1:</strong></p>
  
  <p>I am using DataSet.ReadXmlSchema("...xsd"). From that, I use DataSet.Tables[..] to create DataTable to put the data. Then call DataSet.GetXml() to get the string XML representation.</p>
  
  <p><strong>UPDATES2:</strong></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
  {
      String sXSD = @"C:\WindowsFormsApplication1\WindowsFormsApplication1\XMLFile1.xsd";
      DataSet dsXSD = new DataSet();
      dsXSD.ReadXmlSchema(sXSD);
      int k = 0;
      do
      {
          DataRow d;
          d = dsXSD.Tables["tblUser"].NewRow();
          int i = 0;
          do
          {
              d[i] = k;
              i = (i + 1);
          } while (i &lt; dsXSD.Tables["tblUser"].Columns.Count);
          dsXSD.Tables["tblUser"].Rows.Add(d);
          d = dsXSD.Tables["tblUserRole"].NewRow();
          i = 0;
          do
          {
              d[i] = k;
              i = (i + 1);
          } while (i &lt; dsXSD.Tables["tblUserRole"].Columns.Count);
          dsXSD.Tables["tblUserRole"].Rows.Add(d);
          k = (k + 1);
      } while (k &lt; 3);
      dsXSD.WriteXml("c:\\test.xml");
  
  
  }
  </code></pre>
  
  <p><strong>XSD:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16" ?&gt;
  &lt;xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
    &lt;xsd:element name="tblUser"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="UserID" type="xsd:int" /&gt;
          &lt;xsd:element name="FullName" type="xsd:string" nillable="true" /&gt;
          &lt;xsd:element name="tblUserRole"&gt;
            &lt;xsd:complexType&gt;
              &lt;xsd:sequence&gt;
                &lt;xsd:element name="UserID" type="xsd:int" /&gt;
                &lt;xsd:element name="RoleID" type="xsd:int" /&gt;
              &lt;/xsd:sequence&gt;
            &lt;/xsd:complexType&gt;
          &lt;/xsd:element&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:complexType&gt;
    &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" standalone="yes"?&gt;
  &lt;NewDataSet&gt;
    &lt;tblUser&gt;
      &lt;UserID&gt;0&lt;/UserID&gt;
      &lt;FullName&gt;0&lt;/FullName&gt;
      &lt;tblUserRole&gt;
        &lt;UserID&gt;0&lt;/UserID&gt;
        &lt;RoleID&gt;0&lt;/RoleID&gt;
      &lt;/tblUserRole&gt;
    &lt;/tblUser&gt;
    &lt;tblUser&gt;
      &lt;UserID&gt;1&lt;/UserID&gt;
      &lt;FullName&gt;1&lt;/FullName&gt;
      &lt;tblUserRole&gt;
        &lt;UserID&gt;1&lt;/UserID&gt;
        &lt;RoleID&gt;1&lt;/RoleID&gt;
      &lt;/tblUserRole&gt;
    &lt;/tblUser&gt;
    &lt;tblUser&gt;
      &lt;UserID&gt;2&lt;/UserID&gt;
      &lt;FullName&gt;2&lt;/FullName&gt;
      &lt;tblUserRole&gt;
        &lt;UserID&gt;2&lt;/UserID&gt;
        &lt;RoleID&gt;2&lt;/RoleID&gt;
      &lt;/tblUserRole&gt;
    &lt;/tblUser&gt;
  &lt;/NewDataSet&gt;
  </code></pre>