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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:00:53+00:00 2026-05-23T17:00:53+00:00

I am designing my class model. The serialized message of the class model needs

  • 0

I am designing my class model. The serialized message of the class model needs to be in this format:

<?xml version="1.0" encoding="UTF-8" ?>
<Request>
  <Name>TesterScript</Name>
  <ID>CD_20110628133820576</ID>
  <Type>
    <ItemId>191_20110628T133821</ItemId>
    <ShopId>MyBCShop</ShopId>
    <MessageXml>
    <ChildMessage>
      This is my message
    </ChildMessage>
    </MessageXml>
  </Type>
  <SentTime>2011-06-30T15:27:06-07:00</SentTime>
</Request>

How would I design the classes?
Also what should be the best way to serialize the suggested class model to above XML message? I am thinking of using:

// Serialize the request
XmlSerializer xs = new XmlSerializer(typeof(Request));
StringWriter sw = new StringWriter();
xs.Serialize(sw, dispatchRequest);
string xml = sw.ToString();
return new xml;

Is this the most suitable way?

  • 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-23T17:00:53+00:00Added an answer on May 23, 2026 at 5:00 pm

    I hope my solution is useful ….

    The xml content (i think there is something wrong in your post…)

    <?xml version="1.0" encoding="utf-8" ?>
    <Request>
      <Name>TesterScript</Name>
      <ID>CD_20110628133820576</ID>
      <Type>
        <ItemId>191_20110628T133821</ItemId>
        <ShopId>BARCGB2L</ShopId>
        <MessageXml>
          <ChildMessage>
            This is my message
          </ChildMessage>
        </MessageXml>
      </Type>
      <SentTime>2011-06-30T15:27:06-07:00</SentTime>
    </Request>
    

    The class :

    [XmlRoot("Request")]
    public class SampleClass
    {
        public string Name { get; set; }
        public string ID { get; set; }
        [XmlElement("Type")]
        public SubClass SC { get; set; }
        public string SentTime { get; set; }
    
        public class SubClass
        {
            public string ItemId { get; set; }
            public string ShopId { get; set; }
            [XmlElement("MessageXml")]
            public Sub2Class SC2 { get; set; }
    
            public class Sub2Class
            {
                public string ChildMessage { get; set; }
            }
        }
    }
    

    The Deserialize method:

    public static T DeserializeForXml<T>(string filePath)
        {
            XmlSerializer selializer = new XmlSerializer(typeof(T));
            using (Stream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return (T)selializer.Deserialize(fs);
            }
        }
    

    How to use ?

    SampleClass sc = Utility.DeserializeForXml<SampleClass>("test.xml");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When designing both the domain-model and class-diagrams I am having some trouble understanding what
When designing a new object model I always start with the class diagram function
I'm creating a Trivia app, and need some help designing my model relationships. This
I have Model class like this class ModelName { public static void createTable(SQLiteDatabase db){
In designing a class for customer for example would it make sense to use
I am designing a class for log entries of my mail server. I have
I am currently designing a class library that will provide data to a web
I am designing a class where some methods won't cause any harm if they
Suppose I am designing a class that can handle any database technology to create
I'm wondering how you'd recommend designing a class, given the fact that XNA Framework

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.