Question about XMLDataDocument

M

Mathew Relick

I'm relatively new to this sort of thing, so forgive me if this is
completely off base, but I'm having a problem getting the
XMLDataDocument to do what I need it to.

I have a small test application that has a DataSet with two data
tables, Person and Home. I've setup Home as a child of Person. What
I want to do is to load data into these two tables, and then have the
data document create the xml with the child nodes (home) nested under
the parent node (person). Is this possible??? The code snippet I
have to load and output the xml is as follows:

DsTester ds = new DsTester();
DsTester.PersonDataTable pdt =
(DsTester.PersonDataTable)ds.Tables["Person"];
DsTester.HomeDataTable hdt =
(DsTester.HomeDataTable)ds.Tables["Home"];
pdt.AddPersonRow(12,"John");
hdt.AddHomeRow(1,pdt[0], "MyHome");
XmlDataDocument xdoc = new XmlDataDocument(ds);
System.Diagnostics.Debug.WriteLine(xdoc.OuterXml);


What it outputs is:
<DsTester xmlns="http://tempuri.org/Dataset1.xsd">
<Person>
<PersonID>12</PersonID>
<Name>John</Name>
</Person>
<Home>
<HomeID>1</HomeID>
<PersonID>12</PersonID>
<HomeName>MyHome</HomeName>
</Home>
</DsTester>


What I want it to output is:
<DsTester xmlns="http://tempuri.org/Dataset1.xsd">
<Person>
<PersonID>12</PersonID>
<Name>John</Name>
<Home>
<HomeID>1</HomeID>
<HomeName>MyHome</HomeName>
</Home>
</Person>
</DsTester>



Is this possible, or am I going to have to roll my own?


Thanks!!!
 

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