473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapping dataset tables to XML output

Hi,
I'm really stuck with this one. I have a dataset with two tables. One table
is company data, and the other is contacts. I populate these by using a SP in
SQL Server which returns the two tables in one call. I'm using Microsoft
EnterpriseLibra ry for Data to get the data from SP. It works fine and I get
two tables in the dataset, "Table1" and "Table2".

I then have an XML-file, which will serve as a template to generate the
XML-schema, which I load into the dataset with the InferXmlSchema method.
This gives me a perfectly good looking XML-Schema of how I want the XML-data
to be returned in the Dataset. Although, it appears that I have two schemas.
One that is the schema based on my XML-docuement, and the other which just
seem to be a plain structure of the two tables loaded into the dataset (which
really isn't the way I want to return it) with no relation to eachother.

Anyway, when I try to get the data from the two tables to an
XML-representation, they will not relate to eachother. Both tables will
simply be shown without nesting.
For example, I get this:
<company>
<name>abc</name>
</company>
<contact>
<name>123</name>
</contact>
instead of what I want and the schema I generated says:
<company>
<name>abc</name>
<contacts>
<contact>
<name>123</name>
</contact>
.... here there could be more contacts ...
</contacts>
</company>

I'm really lost here. Where am I going wrong? I have tried to rename the
tables Table1, 2 etc. to the correct names from the schema, company and
contact, but that doesn't work.

I know I can manually create relations with the dataset, but is that really
necessary? The XML-schema says it all how it should be nested. Or is it my SP
that doesn't return the info about how the two tables relate.

What is required for this to work? Can I get it to work by just using the
XML-schema generated for me, or do I have to add the relations between the
tables in code for this to work? Or should I change my SP to return the data
in another way (today it just simply are two selects from the two tables for
a specific company for example).

And, I'm also wondering another thing, which I just as well may ask. Why are
the tables in the dataset named "Table1" and "Table2" etc., instead of their
actual name as used in the SP? Is this the default behaviour that the
tablenames doesn't get returned from the SP in the two resultsets?

Well, if anyone has any hint, please let me know. But, I would like to avoid
adding relationsinform ation for the tables in the code. It really must be
possible for that to be returned automatically from the SP, or I mean, the
actual XML-schema is perfectly fine in defining how the tables should relate?
Or can't it map XML-schema to tables by the names if they are the same?

Thank you for any help!
Oct 6 '06 #1
2 4686
"Henrik" <no*****@nomail x.nowrote in message
news:8B******** *************** ***********@mic rosoft.com...
Hi,
I'm really stuck with this one. I have a dataset with two tables. One
table
is company data, and the other is contacts. I populate these by using a SP
in
SQL Server which returns the two tables in one call. I'm using Microsoft
EnterpriseLibra ry for Data to get the data from SP. It works fine and I
get
two tables in the dataset, "Table1" and "Table2".

I then have an XML-file, which will serve as a template to generate the
XML-schema, which I load into the dataset with the InferXmlSchema method.
This gives me a perfectly good looking XML-Schema of how I want the
XML-data
to be returned in the Dataset. Although, it appears that I have two
schemas.
One that is the schema based on my XML-docuement, and the other which just
seem to be a plain structure of the two tables loaded into the dataset
(which
really isn't the way I want to return it) with no relation to eachother.
You can't load a schema into a dataset to determine how the XML will be
rendered. Loading a schema into a DataSet is for the purpose of configuring
tables and rows and relations.

If you need to return the XML in a different format, you're going to have to
do that on your own. Perhaps you can use an XML stylesheet.

John
Oct 6 '06 #2
Henrik,

If I understand your problem correctly, what I have done to achieve similar
is create a stored procedure (sp) to return the data in XML format using the
FOR XML statement within my sp then

' Create Command object
Dim SqlCmd As New SqlCommand("p_X ML_s", SqlCon)

SqlCmd.CommandT ype = CommandType.Sto redProcedure

' Set up XmlReader
Dim XmlReader As XmlReader = SqlCmd.ExecuteX mlReader

' Get Schema File (name and path)
Dim RelationsSchema As String =
System.Web.Http Context.Current .Server.MapPath (XML-schema)

' Generate DataSet based on Schema provided
Dim MyDataset As New DataSet
MyDataset.ReadX mlSchema(Relati onsSchema)
MyDataset.ReadX ml(XmlReader, XmlReadMode.Fra gment)

' Return DataSet
Return MyDataset

This should work providiing your stored procedure is returning the data
correctly, you may need to change the XmlReadMode, I am using Fragment as my
data does not return a unique root node.
Alex

"Henrik" wrote:
Hi,
I'm really stuck with this one. I have a dataset with two tables. One table
is company data, and the other is contacts. I populate these by using a SP in
SQL Server which returns the two tables in one call. I'm using Microsoft
EnterpriseLibra ry for Data to get the data from SP. It works fine and I get
two tables in the dataset, "Table1" and "Table2".

I then have an XML-file, which will serve as a template to generate the
XML-schema, which I load into the dataset with the InferXmlSchema method.
This gives me a perfectly good looking XML-Schema of how I want the XML-data
to be returned in the Dataset. Although, it appears that I have two schemas.
One that is the schema based on my XML-docuement, and the other which just
seem to be a plain structure of the two tables loaded into the dataset (which
really isn't the way I want to return it) with no relation to eachother.

Anyway, when I try to get the data from the two tables to an
XML-representation, they will not relate to eachother. Both tables will
simply be shown without nesting.
For example, I get this:
<company>
<name>abc</name>
</company>
<contact>
<name>123</name>
</contact>
instead of what I want and the schema I generated says:
<company>
<name>abc</name>
<contacts>
<contact>
<name>123</name>
</contact>
... here there could be more contacts ...
</contacts>
</company>

I'm really lost here. Where am I going wrong? I have tried to rename the
tables Table1, 2 etc. to the correct names from the schema, company and
contact, but that doesn't work.

I know I can manually create relations with the dataset, but is that really
necessary? The XML-schema says it all how it should be nested. Or is it my SP
that doesn't return the info about how the two tables relate.

What is required for this to work? Can I get it to work by just using the
XML-schema generated for me, or do I have to add the relations between the
tables in code for this to work? Or should I change my SP to return the data
in another way (today it just simply are two selects from the two tables for
a specific company for example).

And, I'm also wondering another thing, which I just as well may ask. Why are
the tables in the dataset named "Table1" and "Table2" etc., instead of their
actual name as used in the SP? Is this the default behaviour that the
tablenames doesn't get returned from the SP in the two resultsets?

Well, if anyone has any hint, please let me know. But, I would like to avoid
adding relationsinform ation for the tables in the code. It really must be
possible for that to be returned automatically from the SP, or I mean, the
actual XML-schema is perfectly fine in defining how the tables should relate?
Or can't it map XML-schema to tables by the names if they are the same?

Thank you for any help!
Oct 17 '06 #3

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

Similar topics

4
2477
by: Deepa | last post by:
Hi I have a DataSet file (xml) which I need to convert it into a tab delimited file. I need to write a C# console application for doing the same. Can anyone help me out with the code to do it? I'd appreciate any kind of help. Thanks
3
4580
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. I'm getting some strange results depending the input XML file I use. I was wondering if somebody could help me understand what is going on or point...
1
1449
by: Mark Bosley | last post by:
I have a multiple table dataset that I am attempting access thru XmlDataDocument, and I have read a bit about this (like Rocky Lhotka's article), but I am attempting something outside of the samples I have seen. I can take some Xml like this <DataSet> <DriveOption Available="48" DriveOptions="Right Hand Lead Screw with Standard Pitch" />...
2
9950
by: Wayne Wengert | last post by:
I am attempting to generate an XML file based on the contents of a dataset which contains a parent-child relationship but when I create the output file all I get is the XML header as shown here: <?xml version="1.0" encoding="utf-8"?> <DataSet xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
5
2123
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework or something that completely abstracts you from the persistence details. Are you: 1. Having simple data type interfaces and the data layer know...
2
3111
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it does not seem to be working.
11
19850
by: scorpion53061 | last post by:
Well I had a way to write an array to an excel spreadsheet but on a huge time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It worked fine when i sampled the data to go in but when it all tried to go in it bombed. So I need to write this to a tab delimited file and I sure hope somebody is awake tonight. How do I...
6
2096
by: Ben | last post by:
Hi We have a Dataset that has been populated from the output parameter of a Stored Procedure (@Output). I understand that I can extract a single item when the dataset is populated by a table using this code: CType(objDataSet.Tables("MyTable").Rows(0).Item("MyField"), String)
0
1462
by: marcosalvadeo | last post by:
I have a problem. I created a dataset in visual studio 2005 which use tables of SQL Server Mobile. When I create insert query in the relative TableAdapter, the dataset designer maps the type numeric of SQL Server Mobile as "Object" and not "Decimal". The result of this is that when the debug starts there's an exception because the mapping...
0
7912
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
8202
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. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
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...
0
5390
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
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.