© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
10 replies
Sparky

❔ Is there an easy way to serialize a Dictionary<string, string> to XML nodes?

I'm writing a program that has to produce the following XML:
<Attributes>
    <Color>red</Color>
    <Size>small</Size>
    <Material>plastic</Material>
</Attributes>
<Attributes>
    <Color>red</Color>
    <Size>small</Size>
    <Material>plastic</Material>
</Attributes>

I'm trying to figure out the best data model that can be serialized to something like this. The most obvious choice seems to be a
Dictionary<string, string>
Dictionary<string, string>
, but I can also use a custom class with two properties (Name, Value). I've seen some solutions on stack overflow, but all of them involve creating a bunch of helper classes and writing hundreds of lines of additional code, and I refuse to believe that there is no simpler way of doing this, with Xml attributes or something like that.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ XML Read XML and save as dictionary
C#CC# / help
3y ago
❔ Is there a way to read XML the same way I would read JSON?
C#CC# / help
3y ago
❔ Help with Dictionary<string,string>
C#CC# / help
3y ago