Jump to content
  • Advertisement
Sign in to follow this  
BradDaBug

[.net] XML serialization question

This topic is 4480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!