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

probably a simple question (I hope)

I need to output some related data tables as XML. I have my data adapters
and my dataset with the relations defined. It is certainly simple enough to
use the dataset.WriteXML function. However, this writes the data such that
each
DataTable in the dataset is written one after the other. This is not what I
need. I do not need to be able to load this back into a dataset at a later
time. The XML file and schema I generate will be used to import the data
into another, completely unrelated, system.

Here is a simple example:
Tablename: Customer
Fields: CustomerID
CustomerName

Tablename: Purchases
Fields: CustomerID
PurchaseDate
PurchaseAmount

Relation: A Customer can have many Purchases (one to many)

When I save my dataset to XML it looks something like this:
<Customer>
<CustomerID>1</CustomerID>
<CustomerName>John Doe</CustomerName>
</Customer>
<Customer>
<CustomerID>2</CustomerID>
<CustomerName>Bob Smith</CustomerName>
</Customer>
<Customer>
<CustomerID>3</CustomerID>
<CustomerName>Jane Somebody</CustomerName>
</Customer>
<Purchases>
<CustomerID>1</CustomerID>
<PurchaseDate>2/1/2005</PurchaseDate>
<PurchaseAmount>23.00</PurchaseAmount>
</Purchases>
<Purchases>
<CustomerID>1</CustomerID>
<PurchaseDate>2/5/2005</PurchaseDate>
<PurchaseAmount>123.00</PurchaseAmount>
</Purchases>
<Purchases>
<CustomerID>2</CustomerID>
<PurchaseDate>1/23/2005</PurchaseDate>
<PurchaseAmount>1.00</PurchaseAmount>
</Purchases>

I would like it to look something like below:
<Customer>
<CustomerID>1</CustomerID>
<CustomerName>John Doe</CustomerName>
<Purchases>
<PurchaseDate>2/1/2005</PurchaseDate>
<PurchaseAmount>23.00</PurchaseAmount>
</Purchases>
<Purchases>
<PurchaseDate>2/5/2005</PurchaseDate>
<PurchaseAmount>123.00</PurchaseAmount>
</Purchases>
</Customer>
<Customer>
<CustomerID>2</CustomerID>
<CustomerName>Bob Smith</CustomerName>
<Purchases>
<PurchaseDate>1/23/2005</PurchaseDate>
<PurchaseAmount>1.00</PurchaseAmount>
</Purchases>
</Customer>
<Customer>
<CustomerID>3</CustomerID>
<CustomerName>Jane Somebody</CustomerName>
</Customer>

Can someplease point me in the right direction how to do this (short of
manually building the XML line by line). I have tried for several hours but
feel I am missing something.

Thank in advance,
Lance

Nov 22 '05 #1
7 1671
LeRoy,

The only time I succeeded in that was when I used the designer to create
this.

I thought it was something as creating two datatables using the designer.
Than set the parentchild relation, and than drag the child over the parent.

However I never looked at the created code.

Can you try it yourself?

Cor
Nov 22 '05 #2
Still no luck. I did as you suggested but the XML saved to file still
separates the 2 datatables (the purchases are at the end of the file instead
of embedded in the customers).

Any other ideas from anyone?

Thanks,
Lance

"Cor Ligthert" wrote:
LeRoy,

The only time I succeeded in that was when I used the designer to create
this.

I thought it was something as creating two datatables using the designer.
Than set the parentchild relation, and than drag the child over the parent.

However I never looked at the created code.

Can you try it yourself?

Cor

Nov 22 '05 #3
LeRoy,

This is the page and I know it works, (I tried it a while ago)

(the keyword is nested)

http://msdn.microsoft.com/library/de...xmlschemas.asp

I hope this helps?

Cor
Nov 22 '05 #4
Thanks, but that describes how to make the schema nested. My schema is
nested. However, when I use the dataset.WriteXML the XML produced does not
nest the data.

Lance

"Cor Ligthert" wrote:
LeRoy,

This is the page and I know it works, (I tried it a while ago)

(the keyword is nested)

http://msdn.microsoft.com/library/de...xmlschemas.asp

I hope this helps?

Cor

Nov 22 '05 #5
Lance,
Thanks, but that describes how to make the schema nested. My schema is
nested. However, when I use the dataset.WriteXML the XML produced does
not
nest the data.


This is in the sample on the page I showed you,

\\\
<Customers>
<CustomerID>ANATR</CustomerID>
<CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
<Orders>
<OrderID>10308</OrderID>
<OrderDate>1996-09-18</OrderDate>
<OrderDetails>
<OrderWeight>20kg</OrderWeight>
<ShipVia>International Air</ShipVia> </OrderDetails>
</Orders>
</Customers
///

What is this different from the XML file (beside the tagnames and variables)
as the one you showed as sample in your question.

Cor
Nov 22 '05 #6
You are quite right. That does match the structure of the XML I desire.
However I am still unable to achieve the desired output for some reason.

1. My schema is nested.
2. I use 2 DataAdapters to fill the 2 data tables in the dataset (whose
schema is nested).
3. I call dataset.WriteXML method. The resulting XML is not nested. It
lists all the records in the first table followed by all the records in the
second table (not nested).

I am probably just missing something here but it is driving me crazy trying
to figure this out :-) Any ideas?

Thanks,
Lance

Nov 22 '05 #7
I got it! There is a property on the relation called IsNested. That, of
course, must be set to true.

Thanks,
Lance
Nov 22 '05 #8

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

Similar topics

1
by: Robert Muchacki | last post by:
Hello all! I'm fighting with this little problem. I'm trying to retrieve data from a table in SQL Server 2k. I'm dead. The only result I get is retrieving the headers of the columns - no data in...
7
by: Jim H | last post by:
I'm new to gui programming. I'm just doing some testing with forms. I've dropped a com control on a form. When a user clicks and holds the mouse down on the control I'd like to drag the form...
1
by: jm | last post by:
Easy probably, please read on. I know some of you have commented already about some of my socket question. I appreciate that. I have a Form1: static void Main() { Application.Run(new...
4
by: Tomas Machala | last post by:
Hi, I'm trying to make an application communicating over TCP/IP. It should do only one thing - write received data to console and terminate itself when "exit" received. Problem is that if I send some...
2
by: Ron | last post by:
I want to add radio buttons to a datagrid. The datagrid is displaying 5-10 items, and I want the user to select the desired item via radiobutton. As it is, the user can select as many radiobuttons...
1
by: Tom | last post by:
Hi I have a usercontrol that inherits from System.Windows.Forms.Usercontrol. As the Text property is not visable in the IDE by default i am shadowing the property because i want ot use it on...
2
by: Todd Jaspers | last post by:
Hey guys, I've added a list of items to a listbox in my C#/ASP web form. I allow the user to select a few items, and then click a button. I want to be able to retrieve the items from the list...
0
by: MikeDiver | last post by:
My first problem is that i was working on a project that had two radio buttons in it, i decided to delete one of them and now i cant get the second to activiate without being clicked (the second...
7
by: Dustin MacDonald | last post by:
Hi everyone. This is my first time posting to this newsgroup, and although I maintain my netiquette I might've missed something specific to the newsgroup, so hopefully you can avoid flaming me...
3
maxx233
by: maxx233 | last post by:
Hello, I'm developing a simple program to control a video switcher we have via RS232. All the backend control stuff is figured out just fine, the interface is what's giving me problems! I'm...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.