Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:01:55+00:00 2026-05-15T11:01:55+00:00

Is it possible to implement IXmlSerializable and in my XML file capture an object

  • 0

Is it possible to implement IXmlSerializable and in my XML file capture an object of type Dictionary> ?

I have the following

public class coolio : IXmlSerializable
{
private int a;
private bool b;
private string c;
private Dictionary<string, List<string>> coco;

public coolio(int _a, bool _b, string _c, Dictionary<string, List<string>> _coco)
    {
    a=_a;
    b=_b;
    c=_c;
    coco=_coco;
    }

public System.Xml.Schema.XmlSchema GetSchema()
    {
    return null;
    }

public void WriteXml(XmlWriter writer)
    {
    const string myType = "coolio";
    writer.WriteStartElement(myType);
    writer.WriteAttributeString("a", a.ToString());
    writer.WriteAttributeString("b", b.ToString());
    writer.WriteAttributeString("c", c);

    // How do I add a subelement for Dictionary<string, List<string>> coco?

    writer.WriteEndElement();
    }

public void ReadXml(XmlReader reader)
    {
    if (reader.MoveToContent() != XmlNodeType.Element || reader.LocalName != "coolio") 
                return;
    a= int.Parse(reader["a"]);
    b = bool.Parse(reader["b"]);
    c= reader["c"];

    // How do I read subelement into Dictionary<string, List<string>> coco?
    }
}

But I am stumped as to how I could add the Dictionary> (XML seriliazed to my XML file)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:01:56+00:00Added an answer on May 15, 2026 at 11:01 am
    writer.WriteStartElement("CocoKeys");
    foreach (var kvp in coco)
    {
      writer.WriteStartElement("CocoKey");
      writer.WriteAttributeString("key", kvp.Key);
      writer.WriteStartElement("CoCoValues");
      foreach(string s in kvp.Value)
      {
        writer.WriteStartElement("CoCoValue");
        writer.WriteString(s);
        writer.WriteEndElement();
      }
      writer.WriteEndElement();
      writer.WriteEndElement();
      writer.WriteEndElement();
    }
    

    This should produce something like this:

    <CocoKeys>
      <CocoKey key="sample">
      <CocoValues>
        <CocoValue>Sample1</CocoValue>
        <CocoValue>Sample2</CocoValue>
        <CocoValue>Sample3</CocoValue>
      </CocoKey>
    </CocoKeys>
    

    On the other side, just iterate over it and recostruct it. I hope the code is correct, I did it just by your example. You might have to adjust method calls, but in pseudo it should be correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to implement static class member functions in *.cpp file instead of
Is it possible to implement Delegate methods for FileSystemWatcher? I have a delegate method
Is it possible to implement associative arrays as Selectors and Values. I have an
Does anyone know if it is possible to implement playback of an audio file
Is it possible to implement a multi-threaded class loader in Java? In a meta-driven
Is it possible to raise events to XmlSerializer on a class that implements IXmlSerializable
Is it possible to implement a function to access a private data vector foo
Is it possible to implement something like the following trigger CREATE TRIGGER [tr_AU_ddl_All_Server] ON
Is it possible to implement an anonymous page preview in SiteCore? We have a
Is it possible to implement the following powershell script? The purpose is to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.