I need to build a complex XML document. By complex, it has many elements
embedded within other elements.

At first I was hoping I could build a DataSet, and then just use the
WriteXML method to save the file. Unfortunately, I'm not having much luck
with that (I cannot figure out how to build the parent/child relationships).


Let me give an example.


I need to create the following XML (the format is not up to me, so please
don't suggest that I simplify the output structure, as that is out of my
control):

<document>
<header>
<title>Fred</title>
<page>1</page>
</header>
<item>
<number>123</number>
<name>
<value>test1</value>
</name>
</item>
<item>
<number>456</number>
<name>
<value>test2</value>
</name>
</item>


Now, I can create the <document> and <header>/<item> level elements. But I
cannot seem to create the elements within those (especially <name> in
<item>, as that contains elements itself) using the DataSet object.


What is going to be the best/easiest way to do this?


Thanks!
-Scott

Re: XML - building a complex XML document by Val

Val
Wed Sep 08 20:47:28 CDT 2004

Hi Scott,

What you could do is to create multiple dataTables inside one DataSet. Then
you could create parent-child relations between those tables and then save
dataSet into XML. In this case you should get hierarchical XML output

--
Val Mazur
Microsoft MVP


"Scott Lyon" <scott.RED.lyon.WHITE@rapistan.BLUE.com> wrote in message
news:%23oJyOLelEHA.2892@tk2msftngp13.phx.gbl...
>I need to build a complex XML document. By complex, it has many elements
> embedded within other elements.
>
> At first I was hoping I could build a DataSet, and then just use the
> WriteXML method to save the file. Unfortunately, I'm not having much luck
> with that (I cannot figure out how to build the parent/child
> relationships).
>
>
> Let me give an example.
>
>
> I need to create the following XML (the format is not up to me, so please
> don't suggest that I simplify the output structure, as that is out of my
> control):
>
> <document>
> <header>
> <title>Fred</title>
> <page>1</page>
> </header>
> <item>
> <number>123</number>
> <name>
> <value>test1</value>
> </name>
> </item>
> <item>
> <number>456</number>
> <name>
> <value>test2</value>
> </name>
> </item>
>
>
> Now, I can create the <document> and <header>/<item> level elements. But I
> cannot seem to create the elements within those (especially <name> in
> <item>, as that contains elements itself) using the DataSet object.
>
>
> What is going to be the best/easiest way to do this?
>
>
> Thanks!
> -Scott
>
>



Re: XML - building a complex XML document by Scott

Scott
Thu Sep 09 05:53:48 CDT 2004

How would that work, as I don't have any IDs to determine the parent-child
relationship?

For example, notice in my example (below) how we have a parent element of
<item> with a child element of <name> (just to name one child), which then
has it's own child element of <value>


I can create the <value> and <name> elements easily enough, but I'm unable
to figure out how to tell it that <name> is the parent of <value>. Same for
<name> to <item>.


Thanks!
-Scott


"Val Mazur" <group51a@hotmail.com> wrote in message
news:eaSW47glEHA.3632@TK2MSFTNGP09.phx.gbl...
> Hi Scott,
>
> What you could do is to create multiple dataTables inside one DataSet.
Then
> you could create parent-child relations between those tables and then save
> dataSet into XML. In this case you should get hierarchical XML output
>
> --
> Val Mazur
> Microsoft MVP
>
>
> "Scott Lyon" <scott.RED.lyon.WHITE@rapistan.BLUE.com> wrote in message
> news:%23oJyOLelEHA.2892@tk2msftngp13.phx.gbl...
> >I need to build a complex XML document. By complex, it has many elements
> > embedded within other elements.
> >
> > At first I was hoping I could build a DataSet, and then just use the
> > WriteXML method to save the file. Unfortunately, I'm not having much
luck
> > with that (I cannot figure out how to build the parent/child
> > relationships).
> >
> >
> > Let me give an example.
> >
> >
> > I need to create the following XML (the format is not up to me, so
please
> > don't suggest that I simplify the output structure, as that is out of my
> > control):
> >
> > <document>
> > <header>
> > <title>Fred</title>
> > <page>1</page>
> > </header>
> > <item>
> > <number>123</number>
> > <name>
> > <value>test1</value>
> > </name>
> > </item>
> > <item>
> > <number>456</number>
> > <name>
> > <value>test2</value>
> > </name>
> > </item>
> >
> >
> > Now, I can create the <document> and <header>/<item> level elements. But
I
> > cannot seem to create the elements within those (especially <name> in
> > <item>, as that contains elements itself) using the DataSet object.
> >
> >
> > What is going to be the best/easiest way to do this?
> >
> >
> > Thanks!
> > -Scott
> >
> >
>
>