473,545 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing an XMl file using a specified schema

Help! I created a XML schema with a Visual Studio tools. I'm filling a
dataset with a DataAdapter. Before I use the "WriteXml" method to write the
data to a xml file, I want to map the XSD file I created to the dataset so
that when I do use the "WriteXml" method, the generated xml file will be
properly formatted to the schema I created. I did try using the
"ReadXMLSch ema" but it didn't work. Please help me!
Aug 7 '06 #1
3 4423
You may be approaching this the wrong way, I recently had a problem
going from a dataset to xml and found the columnmapping property of the
dataset in combination with relation objects to work very well

for example:

ds.Relations.Ad d(new DataRelation("A ppsettings AConfiguration" ,
ds.Tables["Appsetting s"].Columns[0],
ds.Tables["AConfiguration "].Columns[0]));
ds.Relations.Ad d(new DataRelation("P rofile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configurat ion"].Columns[1]));

ds.Relations[0].Nested = true;
ds.Relations[1].Nested = true;

ds.Tables["Appsetting s"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[3].ColumnMapping =
MappingType.Sim pleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[3].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[4].ColumnMapping =
MappingType.Sim pleContent ;

the relation objects create the parent child relationship between the
columns, and the nesting property sets it up for use in your XML
document.
the columnmapping stuff is pretty self explanatory.

Hope this helps.

Eric wrote:
Help! I created a XML schema with a Visual Studio tools. I'm filling a
dataset with a DataAdapter. Before I use the "WriteXml" method to write the
data to a xml file, I want to map the XSD file I created to the dataset so
that when I do use the "WriteXml" method, the generated xml file will be
properly formatted to the schema I created. I did try using the
"ReadXMLSch ema" but it didn't work. Please help me!
Aug 7 '06 #2
I don't really understand what you are trying to expain....
Here is an example of what i am doing:

This is the xsd:
<xs:element name="Flight" type="Flight"/>
<xs:complexTy pe name="Flight">
<xs:sequence>
<xs:element name="Departure Date" type="xs:date" />
<xs:element name="Origin" type="xs:string " />
<xs:element name="Destinati on" type="xs:string " />
<xs:element name="OutOfStoc k" type="OutOfStoc k" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="FlightNo" type="xs:string " />
<xs:attribute name="LegIndex" type="xs:int" />
</xs:complexType>

<xs:complexTy pe name="OutOfStoc k">
<xs:sequence>
<xs:element name="Product" type="xs:int" />
<xs:element name="Row" type="xs:string " />
</xs:sequence>
</xs:complexType>

Here is when i fill the dataset:
DataSet ds = new DataSet();
ds.ReadXmlSchem a(@"E:\Schema.x sd");
SqlConnection conn = getConnection;
SqlDataAdapter da = new SqlDataAdapter( "select * from
vFlights", conn);
da.Fill(ds, "Flight");
ds.WriteXml("fl ights.xml");

My problem is that the "OutOfStock " element doesn't show, it just shows the
"Product" and "Row" but there are not nested inside the "OutOfStock " tag. I
look at the schema generated after with a ds.WriteXMLSche ma(".."); and it
seemed to take into consideration the specified schema but it also overloaded
with its owe...

It generated this:
<Flight FlightNo="222" LegIndex="1">
<DepartureDate> 2006-07-25</DepartureDate>
<Origin>RRR</Origin>
<Destination>GG G</Destination>
<Row>23</Row>
<Product>1</Product>
</Flight>

But i want it to generate this:
<Flight FlightNo="222" LegIndex="1">
<DepartureDate> 2006-07-25</DepartureDate>
<Origin>RRR</Origin>
<Destination>GG G</Destination>
<OutOfStock>
<Row>23</Row>
<Product>1</Product>
</OutOfStock>
</Flight>

thanks, maybe this will clarify things!
"rhaazy" wrote:
You may be approaching this the wrong way, I recently had a problem
going from a dataset to xml and found the columnmapping property of the
dataset in combination with relation objects to work very well

for example:

ds.Relations.Ad d(new DataRelation("A ppsettings AConfiguration" ,
ds.Tables["Appsetting s"].Columns[0],
ds.Tables["AConfiguration "].Columns[0]));
ds.Relations.Ad d(new DataRelation("P rofile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configurat ion"].Columns[1]));

ds.Relations[0].Nested = true;
ds.Relations[1].Nested = true;

ds.Tables["Appsetting s"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[3].ColumnMapping =
MappingType.Sim pleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[3].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[4].ColumnMapping =
MappingType.Sim pleContent ;

the relation objects create the parent child relationship between the
columns, and the nesting property sets it up for use in your XML
document.
the columnmapping stuff is pretty self explanatory.

Hope this helps.

Eric wrote:
Help! I created a XML schema with a Visual Studio tools. I'm filling a
dataset with a DataAdapter. Before I use the "WriteXml" method to write the
data to a xml file, I want to map the XSD file I created to the dataset so
that when I do use the "WriteXml" method, the generated xml file will be
properly formatted to the schema I created. I did try using the
"ReadXMLSch ema" but it didn't work. Please help me!

Aug 7 '06 #3
What I am explaining is that you don't need a schema to generate an XML
document from a dataset.

You can use the column mapping property of the dataset like this:
Dataset.Tables["tablename"].Columns["columname"].ColumnMapping =
MappingType.Att ribute ;

Once you assign all the needed columsn to what they need to be you can
use the relation object to create the "nesting" affect of the XML
document.

so for what you want to do it would like something like this:

ds.Relations.Ad d(new DataRelation("n ameofrelation",
dataset.Tables["tablename"].Columns[parentcolumnind ex],
ds.Tables["tablename"].Columns[childcolumninde x]));

So you would want the values for flight number to be the parent of all
the other stuff, and you would then create another relation to make row
and product be part of outofstock.

Then you can set the relation to be nested as i demonstrated above,
this is specifically for formatting the XML document.

What I am suggesting may be way out of context for what you need, and
may be unnecessary to fix what might be a simple problem with what you
already have, I am merely offering a different approach to the
situation.
But i want it to generate this:
<Flight FlightNo="222" LegIndex="1">
<DepartureDate> 2006-07-25</DepartureDate>
<Origin>RRR</Origin>
<Destination>GG G</Destination>
<OutOfStock>
<Row>23</Row>
<Product>1</Product>
</OutOfStock>
</Flight>

thanks, maybe this will clarify things!
"rhaazy" wrote:
You may be approaching this the wrong way, I recently had a problem
going from a dataset to xml and found the columnmapping property of the
dataset in combination with relation objects to work very well

for example:

ds.Relations.Ad d(new DataRelation("A ppsettings AConfiguration" ,
ds.Tables["Appsetting s"].Columns[0],
ds.Tables["AConfiguration "].Columns[0]));
ds.Relations.Ad d(new DataRelation("P rofile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configurat ion"].Columns[1]));

ds.Relations[0].Nested = true;
ds.Relations[1].Nested = true;

ds.Tables["Appsetting s"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[3].ColumnMapping =
MappingType.Sim pleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[3].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[4].ColumnMapping =
MappingType.Sim pleContent ;

the relation objects create the parent child relationship between the
columns, and the nesting property sets it up for use in your XML
document.
the columnmapping stuff is pretty self explanatory.

Hope this helps.

Eric wrote:
Help! I created a XML schema with a Visual Studio tools. I'm filling a
dataset with a DataAdapter. Before I use the "WriteXml" method to write the
data to a xml file, I want to map the XSD file I created to the dataset so
that when I do use the "WriteXml" method, the generated xml file will be
properly formatted to the schema I created. I did try using the
"ReadXMLSch ema" but it didn't work. Please help me!
Aug 7 '06 #4

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

Similar topics

0
1572
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema specified in the main file. At some point in the schema I would add a choice element that would either have a tag that specifies an external file...
2
10741
by: Vagabond Software | last post by:
I have translated a DTD to an XML Schema (XSD) file by hand, and the Schema View in Visual Studio .NET 2003 seems to diplay everything properly. However, when I specify the schemalocation in my xml files, VS.NET still reports that no schema could be located. Here are the relevant (maybe) portions of the files: FROM THE SCHEMA FILE...
0
1198
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema specified in the main file. At certain points in the schema I would add a choice element that would either have a tag that specifies an external...
0
1340
by: Andrius | last post by:
Hello, having some problems by writing XML file by XML schema. using strongly typed datasets. Schema: <?xml version="1.0" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:include schemaLocation="types.xsd" />
1
4126
by: dpakpaul | last post by:
Hi, I have an XSD schema where I have attributes that are declared to contain non string values such as integers etc. Take for example, this declaration - <xs:attribute name="IsThisTrue" type="xs:boolean" /> Now, I want to write or modify an XML document using the DOM API (using C#) where this attribute will be given a boolean value....
0
1004
by: Lindy | last post by:
I have a schema file called asc.xsd which I have added to my project .Net project (VB). I am using XMLTextWriter in order to create/write data to a new XML file. Is there a way to access the elements, etc. from this schema in order to simplify my writing of the elements to the new XML file? If so, how would I do this? When I look at the...
13
2877
by: Jerry C | last post by:
I am using some sample code from gotdotnet to Create DataSet mappings from a xsd schema. I am geting this error. code and error below. I might mention there is also a publictypelibrary file with this file I may have to use it in some way. I am very new at XML so some examples or articles would be helpfull. The error is:
6
1190
by: Andy B | last post by:
I need to make sure that a file saved in a particular place is a valid xml file that fits a certain schema. Where would I get started doing this? The original file would have been created and saved with a dataset.
0
7465
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, 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...
0
7398
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...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
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...
0
4944
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...
0
3449
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...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.