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

  • SEARCH
  • Home
  • 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 1838448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:28:44+00:00 2026-05-17T06:28:44+00:00

Some background: We have some entity classes need to be serialized, so we implement

  • 0

Some background:

We have some entity classes need to be serialized, so we implement the entity class as following in the first edition:

[XmlType("FooElement")]
public class Foo
{
    [XmlText]
    public string Text { get; set; }
}

The serialized XML string should be:

<?xml version="1.0" encoding="gb2312"?>
<FooElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" mlns:xsd="http://www.w3.org/2001/XMLSchema">foo</FooElement>

But we need to make the Text property as read only, so we change the Foo class to implement the IXmlSerializable interface as following:

[Serializable]
public class Foo : IXmlSerializable
{
    public Foo()
    { }

    public Foo(string text)
    {
        Text = text;
    }

    public string Text { get; private set; }

    public XmlSchema GetSchema()
    {
        return null;
    }

    public void ReadXml(XmlReader reader)
    {
        Text = reader.Value;
    }

    public void WriteXml(XmlWriter writer)
    {
        writer.WriteValue(Text);
    }
}

Then the serialized XML string was also changed as following:

<?xml version="1.0" encoding="gb2312"?><Foo>foo</Foo>

Is there any way to change the tag name from “<Foo>foo</Foo>” to “<FooElement>foo</FooElement>“?

  • 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-17T06:28:44+00:00Added an answer on May 17, 2026 at 6:28 am

    I guess, XmlRootAttribute should play well with IXmlSerializable.

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

Sidebar

Related Questions

First some brief background: I have an existing ASP.NET MVC 1 application using Entity
Some setup background first: I have a cronjob which runs a PHP file called
Hi and thanks for your attention. First some background on the question: I have
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
Background: Silverlight 4 - RIA - Entity Framework 4 Description: I have some deletion
First some background: I have a website using ASP.NET web forms + jQuery 1.6.4
First, some background: I have a Company model, a Project model and a Task
Some background: we have a windows application (c#) that locate in the system try.
I have one AlertDialog which is working fine.I have set some background images to

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.