473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataSet changes schema of XML file

I’d like to use the DataSet as the container for the XML files conforming to
some schema. The problem is, that the operation of reading the XML file into
the DataSet having its schema and then writing it back to the file makes it
invalid, not obeying rules of this schema.

Here is the simple test program performing this operation.
__________________________________________________
using System;
using System.Data;
namespace DataSetTest
{
class Program
{
static void Main(string[] args)
{
DataSet DS = new DataSet();
DS.ReadXmlSchema ("XMLSchema1.xsd");
DS.ReadXml("XmlFile1.xml", XmlReadMode.IgnoreSchema);
DS.WriteXml("XmlFile2.xml", XmlWriteMode.IgnoreSchema);
}
}
}
__________________________________________________

The schema is contained in the XMLSchema1.xsd file:
__________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="ct" />
<xs:element name="B" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ct">
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:schema>
__________________________________________________

Here is the valid XML file XMLFile1.xml:
__________________________________________________
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns="http://tempuri.org/XMLSchema1.xsd">
<A attribute1 ="att"/>
<B>some text</B>
</Root>
__________________________________________________

After transformation we get the XMLFile2.xml, which is invalid:
__________________________________________________
<?xml version="1.0" standalone="yes"?>
<XMLSchema1 xmlns="http://tempuri.org/XMLSchema1.xsd">
<Root>
<B>some text</B>
<A attribute1="att" />
</Root>
</XMLSchema1>
__________________________________________________

The XML is invalid because:
1. The enclosing XMLSchema1 element was added, which is not included in the
schema. This is not difficult to correct this by simple post processing, but
it would be more elegant, if there was a way of avoiding this.
2. The elements A and B have changed order although the schema organizes
them in the sequence structure. This happens, when sequence contains
intermixed simple and complex elements. WriteXml method always outputs simple
elements before complex, disregarding schema. I could not find any trivial
method of correcting this. It seems that the information about the order is
lost in the DataSet for such case.

I’ll be obliged for suggestions.

Apr 28 '06 #1
2 1671
What version of the framework are you using?
"MaLec" <Ma***@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
I'd like to use the DataSet as the container for the XML files conforming to some schema. The problem is, that the operation of reading the XML file into the DataSet having its schema and then writing it back to the file makes it invalid, not obeying rules of this schema.

Here is the simple test program performing this operation.
__________________________________________________
using System;
using System.Data;
namespace DataSetTest
{
class Program
{
static void Main(string[] args)
{
DataSet DS = new DataSet();
DS.ReadXmlSchema ("XMLSchema1.xsd");
DS.ReadXml("XmlFile1.xml", XmlReadMode.IgnoreSchema);
DS.WriteXml("XmlFile2.xml", XmlWriteMode.IgnoreSchema);
}
}
}
__________________________________________________

The schema is contained in the XMLSchema1.xsd file:
__________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="ct" />
<xs:element name="B" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ct">
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:schema>
__________________________________________________

Here is the valid XML file XMLFile1.xml:
__________________________________________________
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns="http://tempuri.org/XMLSchema1.xsd">
<A attribute1 ="att"/>
<B>some text</B>
</Root>
__________________________________________________

After transformation we get the XMLFile2.xml, which is invalid:
__________________________________________________
<?xml version="1.0" standalone="yes"?>
<XMLSchema1 xmlns="http://tempuri.org/XMLSchema1.xsd">
<Root>
<B>some text</B>
<A attribute1="att" />
</Root>
</XMLSchema1>
__________________________________________________

The XML is invalid because:
1. The enclosing XMLSchema1 element was added, which is not included in the schema. This is not difficult to correct this by simple post processing, but it would be more elegant, if there was a way of avoiding this.
2. The elements A and B have changed order although the schema organizes
them in the sequence structure. This happens, when sequence contains
intermixed simple and complex elements. WriteXml method always outputs simple elements before complex, disregarding schema. I could not find any trivial
method of correcting this. It seems that the information about the order is lost in the DataSet for such case.

I'll be obliged for suggestions.

May 11 '06 #2
Environment.Version.ToString() returns: 2.0.50727.42

"Zafar Abbas" wrote:
What version of the framework are you using?
"MaLec" <Ma***@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
I'd like to use the DataSet as the container for the XML files conforming

to
some schema. The problem is, that the operation of reading the XML file

into
the DataSet having its schema and then writing it back to the file makes

it
invalid, not obeying rules of this schema.

Here is the simple test program performing this operation.
__________________________________________________
using System;
using System.Data;
namespace DataSetTest
{
class Program
{
static void Main(string[] args)
{
DataSet DS = new DataSet();
DS.ReadXmlSchema ("XMLSchema1.xsd");
DS.ReadXml("XmlFile1.xml", XmlReadMode.IgnoreSchema);
DS.WriteXml("XmlFile2.xml", XmlWriteMode.IgnoreSchema);
}
}
}
__________________________________________________

The schema is contained in the XMLSchema1.xsd file:
__________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="ct" />
<xs:element name="B" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ct">
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:schema>
__________________________________________________

Here is the valid XML file XMLFile1.xml:
__________________________________________________
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns="http://tempuri.org/XMLSchema1.xsd">
<A attribute1 ="att"/>
<B>some text</B>
</Root>
__________________________________________________

After transformation we get the XMLFile2.xml, which is invalid:
__________________________________________________
<?xml version="1.0" standalone="yes"?>
<XMLSchema1 xmlns="http://tempuri.org/XMLSchema1.xsd">
<Root>
<B>some text</B>
<A attribute1="att" />
</Root>
</XMLSchema1>
__________________________________________________

The XML is invalid because:
1. The enclosing XMLSchema1 element was added, which is not included in

the
schema. This is not difficult to correct this by simple post processing,

but
it would be more elegant, if there was a way of avoiding this.
2. The elements A and B have changed order although the schema organizes
them in the sequence structure. This happens, when sequence contains
intermixed simple and complex elements. WriteXml method always outputs

simple
elements before complex, disregarding schema. I could not find any trivial
method of correcting this. It seems that the information about the order

is
lost in the DataSet for such case.

I'll be obliged for suggestions.


May 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wil | last post by:
I'm very new to developing in .NET and even newer to XML. The past few days have been pretty frustrating for me because I'm trying to perform a transform on data in a dataset and it's not working....
1
by: Patrik | last post by:
Hi I want to return a dataset from a webservice and exclude the schema. How can I do this? /Patrik
4
by: Brian Keating | last post by:
wonder if anyone can help me here, i've a framework 1.1 dataset which i serialize in framework 1.1 and deserialize in framework 2.0. This is fine, problem is that i want to modify some of the...
4
by: Sindarian | last post by:
This just seems like the most basic thing, but I can't find a simple description of this process anywhere and in here, everone is talking about going the other way :( I had .NET create an XML...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
4
by: Robert Bravery | last post by:
Hi All, I'm New to VS.net. Trying to figure out this new dataset thingy. Ok so I add a dataadapter with all the correct properties for a table. Then generate the dataset. Now open the dataset and...
11
by: MurdockSE | last post by:
Greetings. My Situation: // I have an .xml file that I am reading into a dataset in the following code - DataSet ds = new DataSet("MyDataset"); ds.ReadXml(@"c:\data\"+cmyxmlfilename);
4
by: Al | last post by:
I have this scenario: 1. XML file with schema and data is created from SQL Server tables. XML file contains 6 tables, some of them have rows, some of them are empty. 2. XML file is given to the...
1
by: GoogleGroups | last post by:
It seems like this should be easy, but it has proven to be quite painful. I have an existing dataset, which I used the GetChanges and WriteXML functions upon to write out a DiffGram to a local...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.