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.ReadXmlSchem a ("XMLSchema1.xs d");
DS.ReadXml("Xml File1.xml", XmlReadMode.Ign oreSchema);
DS.WriteXml("Xm lFile2.xml", XmlWriteMode.Ig noreSchema);
}
}
}
_______________ _______________ _______________ _____
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"
elementFormDefa ult="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="ht tp://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:complexTy pe name="ct">
<xs:attribute name="attribute 1" 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. 2 1699
What version of the framework are you using?
"MaLec" <Ma***@discussi ons.microsoft.c om> wrote in message
news:F7******** *************** ***********@mic rosoft.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.ReadXmlSchem a ("XMLSchema1.xs d"); DS.ReadXml("Xml File1.xml", XmlReadMode.Ign oreSchema); DS.WriteXml("Xm lFile2.xml", XmlWriteMode.Ig noreSchema); } } } _______________ _______________ _______________ _____
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" elementFormDefa ult="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="ht tp://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:complexTy pe name="ct"> <xs:attribute name="attribute 1" 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.
Environment.Ver sion.ToString() returns: 2.0.50727.42
"Zafar Abbas" wrote: What version of the framework are you using?
"MaLec" <Ma***@discussi ons.microsoft.c om> wrote in message news:F7******** *************** ***********@mic rosoft.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.ReadXmlSchem a ("XMLSchema1.xs d"); DS.ReadXml("Xml File1.xml", XmlReadMode.Ign oreSchema); DS.WriteXml("Xm lFile2.xml", XmlWriteMode.Ig noreSchema); } } } _______________ _______________ _______________ _____
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" elementFormDefa ult="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="ht tp://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:complexTy pe name="ct"> <xs:attribute name="attribute 1" 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
Basically, all of the data is stored in an Access .mdb that is read into a
dataset when the application is loaded. There are some minor changes to the
schema between what is in the physical database to accomodate some things
that Access just...
|
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
|
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 records in
framework 2.0 and serialize the data so framework 1.1 can deserialize it and
do what it required.
Is this possible?
|
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 Schema file (xsd) for a table
in my database. I then create a DataSet that contains 1 row of data from that
same table. I want to use this DataSet along with the Schema file to create
an XML file that ACTUALLY CONTAINS THE DATA. Simple huh: DataSet +...
|
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 which indexes
computer magazine articles for personal reference.
I am developing a Visual Basic.NET program whose sole
purpose is to enter new records into the database. No
updates to existing entries, no deletions, and no display
| |
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 drag another table from the
server explorer, set up some relations there. Set up two grids, one a s a
parent one as a chgild. Fill the dataset, run the form
But my child grid never gets any records.
I then added another datadapter for the child...
|
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);
|
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 person with Pocket PC.
3. XML file is used to populate DataSet on the Pocket PC.
4. User adds new rows, changes values, deletes some rows.
5. Altered dataset is saved back to XML file.
6. XML file is given back to the person who initially created...
|
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 XML file. I want to
use this same dataset (in another instance of the application) and the
DiffGram to display the changes in the DataGridView as they existed
after the user made his/her change.
In English:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |