[.net] XML serialization question

Started by
1 comment, last by BradDaBug 18 years, 1 month ago
I'm trying to serialize a class, and I want the resulting XML to look like this (actual element and attribute names aren't that important, I'm just interested in the structure):
<root>
    <someArray someAttribute = "something">
        <blah>something</blah>
        <blah>something else</blah>
    </someArray>
</root>
If I didn't need that someAttribute stuck in there this would be trivial, since someArray could just be an actual array in a class called root. But I cannot figure out any way to produce XML that looks like that, with the attribute added. Any clues?
I like the DARK layout!
Advertisement
This link seems like it has what you are looking for.
http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236

Particularily the attribute called XmlAttribute.

You might want to group your array up into a class or struct with your array in to get this to work.

Sorry, if this wasn't more help. I like to do this kind of thing the hard way and write this kind of thing using the XmlDocument and XPathDocument classes along with custom code to read and write the values.
Oh, okay. That was easy. I didn't realize you could put [XmlElement] on top of an array. I was only ever trying [XmlArrayItem]. Thanks!
I like the DARK layout!

This topic is closed to new replies.

Advertisement