xml serialization

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to serialize my class to the following XML format (... means more):
<a>
<b b1="1" b2="2" b3="3>
<c c1 = "a" />
<c c1 = "b" />
...
</b>
<b b1 = "4" b2 = "5" b3 = "6">
<c c1 = "c" />
<c c1 = "d" />
...
</b>
...
</a>

I am able to get almost everything but <c c1="" /> node. I mean, I don't
know how to make <c> as the sub-node of <b>.

Can this be done in C#? Or XML serialization can only generate 2 layer of
XML?

Please advice, thank you.
-P
 
How are you serializing this? I mean, are y ou letting the XmlSerializer
create the xml file, or are you tying to create it by hand?

-James
 
The simplest way would be to make all the data contained in "c" a separate
class or struct having its own XML serialization attributes properly set.
Then, expose the instance of this class from the main class as a read-write
public property and it should be automatically serialized below the "c"
node.
 
Back
Top