Sign in to follow this  
BradDaBug

[.net] XML serialization question

Recommended Posts

BradDaBug    913
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?

Share this post


Link to post
Share on other sites
BradSnobar    232
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.

Share this post


Link to post
Share on other sites
BradDaBug    913
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this