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
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