473,396 Members | 1,891 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,396 software developers and data experts.

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
"ReadXMLSchema" but it didn't work. Please help me!
Aug 7 '06 #1
3 4410
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.Add(new DataRelation("Appsettings AConfiguration",
ds.Tables["Appsettings"].Columns[0],
ds.Tables["AConfiguration"].Columns[0]));
ds.Relations.Add(new DataRelation("Profile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configuration"].Columns[1]));

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

ds.Tables["Appsettings"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[3].ColumnMapping =
MappingType.SimpleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[3].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[4].ColumnMapping =
MappingType.SimpleContent ;

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
"ReadXMLSchema" 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:complexType name="Flight">
<xs:sequence>
<xs:element name="DepartureDate" type="xs:date" />
<xs:element name="Origin" type="xs:string" />
<xs:element name="Destination" type="xs:string" />
<xs:element name="OutOfStock" type="OutOfStock" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="FlightNo" type="xs:string" />
<xs:attribute name="LegIndex" type="xs:int" />
</xs:complexType>

<xs:complexType name="OutOfStock">
<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.ReadXmlSchema(@"E:\Schema.xsd");
SqlConnection conn = getConnection;
SqlDataAdapter da = new SqlDataAdapter("select * from
vFlights", conn);
da.Fill(ds, "Flight");
ds.WriteXml("flights.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.WriteXMLSchema(".."); 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>GGG</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>GGG</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.Add(new DataRelation("Appsettings AConfiguration",
ds.Tables["Appsettings"].Columns[0],
ds.Tables["AConfiguration"].Columns[0]));
ds.Relations.Add(new DataRelation("Profile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configuration"].Columns[1]));

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

ds.Tables["Appsettings"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[3].ColumnMapping =
MappingType.SimpleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[3].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[4].ColumnMapping =
MappingType.SimpleContent ;

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
"ReadXMLSchema" 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.Attribute ;

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.Add(new DataRelation("nameofrelation",
dataset.Tables["tablename"].Columns[parentcolumnindex],
ds.Tables["tablename"].Columns[childcolumnindex]));

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>GGG</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.Add(new DataRelation("Appsettings AConfiguration",
ds.Tables["Appsettings"].Columns[0],
ds.Tables["AConfiguration"].Columns[0]));
ds.Relations.Add(new DataRelation("Profile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configuration"].Columns[1]));

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

ds.Tables["Appsettings"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[3].ColumnMapping =
MappingType.SimpleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[3].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[4].ColumnMapping =
MappingType.SimpleContent ;

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
"ReadXMLSchema" 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
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...
2
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...
0
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...
0
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">...
1
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"...
0
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...
13
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.