probably a simple question (I hope)

G

Guest

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
 
C

Cor Ligthert

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
 
G

Guest

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
 
G

Guest

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
 
C

Cor Ligthert

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
 
G

Guest

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
 
G

Guest

I got it! There is a property on the relation called IsNested. That, of
course, must be set to true.

Thanks,
Lance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top