XML - building a complex XML document

  • Thread starter Thread starter Scott Lyon
  • Start date Start date
S

Scott Lyon

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