Dataset.WriteXml writes data in wrong order

V

Vaibhav

Hi all.

I am trying to read an xml and then write it. Thre Read xml is from
an xml generated by a tool. I have attached a code snipet. The peoblem is
when i write the xml from dataset in writes xml in improper order. Here's the
code snipet...

private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string val = string.Empty;

ds.EnforceConstraints = false;

try
{
ds.ReadXmlSchema(@"D:\Test.xsd");
ds.ReadXml(@"D:\SampleTest.xml");

foreach (DataRelation relation in ds.Relations)
{
relation.Nested = true;

}


ds.WriteXml(@"D:\OutPut.xml");
ds.Clear();
}

After executing this when i try to read the xmlwritten by dataset it fails
validation.
The Xsd has a structure

Root --- C1 (complex type)
| --- Name
|--- C2 (complex Type)
When i write xml name element comes before C1
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi all.

         I am trying to read an xml and then write it. Thre Read xml is from
an xml generated by a tool. I have attached a code snipet. The peoblem is
when i write the xml from dataset in writes xml in improper order. Here'sthe
code snipet...

 private void Form1_Load(object sender, EventArgs e)
 {
            DataSet ds = new DataSet();
            string val = string.Empty;

            ds.EnforceConstraints = false;

            try
            {
                ds.ReadXmlSchema(@"D:\Test.xsd");
                ds.ReadXml(@"D:\SampleTest.xml");

                foreach (DataRelation relation in ds.Relations)
                {
                    relation.Nested = true;

                }

                ds.WriteXml(@"D:\OutPut.xml");
                ds.Clear();

}

After executing this when i try to read the xmlwritten by dataset it fails
validation.
The Xsd has a structure

Root --- C1   (complex type)
      | --- Name
      |---  C2   (complex Type)
When i write xml name element comes before C1

Try WriteXml( "file" , XmlWriteSchema.WriteSchema);
 
Top