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 7908857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:07:37+00:00 2026-06-03T12:07:37+00:00

I am using the following code to Serialize / Deserialize from object to XML

  • 0

I am using the following code to Serialize / Deserialize from object to XML

using System.Runtime.Serialization;
public static string Serialize<T>(this T obj)
        {
            var serializer = new DataContractSerializer(obj.GetType());
            using (var writer = new StringWriter())
            using (var stm = new XmlTextWriter(writer))
            {
                serializer.WriteObject(stm, obj);
                return writer.ToString();
            }
        }

        public static T Deserialize<T>(this string serialized)
        {
            var serializer = new DataContractSerializer(typeof(T));
            using (var reader = new StringReader(serialized))
            using (var stm = new XmlTextReader(reader))
            {
                return (T)serializer.ReadObject(stm);
            }
        }

To make this code work with IDictionary, i have the following custom Dictionary class:

[CollectionDataContract(Name = "Kenan", ItemName="Items", KeyName="Row", Namespace="spell", ValueName="Values")]
public class CustomRowList : Dictionary<RowXML, List<ColumnXML>>
{

}

The problem is, that when the code outputs my

Dictionary<RowXML, List<ColumnXML>>

it looks like this:

enter image description here

I do not need the <Items> and <Values> nodes. Instead, i would like it for output it as:

<RowList>
<Row>
<Title></Title>
<Help_Text></Help_Text>
<ClassName></ClassName>
<ColumnList>
<Column>
<ClassName></ClassName>
<Help_Text></Help_Text>
<Title></Title>
</Column>
<Column>
...

How can i make DataContractSerializer format my Dictionary in this way? I tried setting the

ItemName

And

ValueName

on

[CollectionDataContract]

Properties to blank, but this didnt work.

  • 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-06-03T12:07:38+00:00Added an answer on June 3, 2026 at 12:07 pm

    Looks like, you want to customize the xml output of your collection class. Only way to achieve this expected output is to implement the IXmlSerializable interface as below.

    [CollectionDataContract(Name = "Kenan", ItemName="Items", KeyName="Row", Namespace="spell", ValueName="Values")]
    public class CustomRowList : Dictionary<RowXML, List<ColumnXML>>, IXmlSerializable 
    {
    
    }
    

    Please look here for more information

    Proper way to implement IXmlSerializable?

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

Sidebar

Related Questions

I am using following code to get List from xml file - public static
I am using the following code to serialize an object to XML, StringBuilder sb
I am using following code to remove some specific nodes from xml file..It show
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using following code but cannot return data from MySQL. This is the output:
I need to serialize and deserialize an object that contains an System.Uri property using
I am using the following code to serialize an object and to attach it
I am using a custom serializer in c# in order to serialize/deserialize an object
How can I de-serialize a json object sent from javascript (using jquery.ajax) to a
I am using the following code to create an xml document - XmlSerializerNamespaces ns

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.