nesting XML nodes

B

bill

I am using ADO.net in VB.NET. I'm trying to export relational data from SQL
Server 2000 to XML with appropriate nesting.

I have included sample code below. Using a Northwind example for clarity,
the XML output is not nested - Customers are presented first, and then
Orders are presented at the same level as Customers. I want the Orders
nested in the correct Customers.

Is there a way to do this using .NET?

Thanks
Bill

Code:
Sub ExportToXML()
Dim custDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Customers", SqlConnection1)
Dim orderDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Orders", SqlConnection1)
SqlConnection1.Open()
Dim custDS As DataSet = New DataSet
custDA.Fill(custDS, "Customers")
orderDA.Fill(custDS, "Orders")
Dim custOrderRel As DataRelation =
custDS.Relations.Add("CustOrders", _

custDS.Tables("Customers").Columns("CustomerID"), _

custDS.Tables("Orders").Columns("CustomerID"))
custDS.WriteXml("c:\data\Output.xml")
End Sub

[OUTPUT]
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<Customers>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
...
</Customers>
<Orders>
<OrderID>10643</OrderID>
<CustomerID>ALFKI</CustomerID>
...
</Orders>
</NewDataSet>


[DESIRED OUTPUT]
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<Customers>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
...
<Orders>
<OrderID>10643</OrderID>
<CustomerID>ALFKI</CustomerID>
...
</Orders>
</Customers>
</NewDataSet>
 
B

bill

I found the answer - custOrderRel.nested = true. I should've looked harder
before posting.
 

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