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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:14:50+00:00 2026-05-18T04:14:50+00:00

what is Difference between using XMLRoot/XMLElement and using Serializable() attributes? how do i know

  • 0

what is Difference between using XMLRoot/XMLElement and using Serializable() attributes?
how do i know when to use each ?

  • 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-18T04:14:51+00:00Added an answer on May 18, 2026 at 4:14 am

    Here is a less than in depth description, but I think a good starting point.

    XmlRootAttribute – Is used to provide schema information for the class that is going to be the root element of the object graph being serialized. This can only be applied to classes, structs, enums, interfaces of return values.

    XmlElementAttribute – Provides schema information for properties of a class controlling how they are serialized as child elements. This attribute can only be applied to fields (class variable members), properties, parameters and return values.

    The first two XmlRootAttribute and XmlElementAttribute relate to the XmlSerializer.
    While the next, is used by the runtime formatters and does not apply when using XmlSerialization.

    SerializableAtttrible – Is used to indicate that the type can be serialized by the runtime formatters like SoapFormatter or BinaryFormatter. This is only required if you need to serialize the type using one of the formatters and can be applied to delegates, enums, structs and classes.

    Here is a quick example that might help clarify the above.

    // This is the root of the address book data graph
    // but we want root written out using camel casing
    // so we use XmlRoot to instruct the XmlSerializer
    // to use the name 'addressBook' when reading/writing
    // the XML data
    [XmlRoot("addressBook")]
    public class AddressBook
    {
      // In this case a contact will represent the owner
      // of the address book. So we deciced to instruct
      // the serializer to write the contact details out
      // as <owner>
      [XmlElement("owner")]
      public Contact Owner;
    
      // Here we apply XmlElement to an array which will
      // instruct the XmlSerializer to read/write the array
      // items as direct child elements of the addressBook
      // element. Each element will be in the form of 
      // <contact ... />
      [XmlElement("contact")]
      public Contact[] Contacts;
    }
    
    public class Contact
    {
      // Here we instruct the serializer to treat FirstName
      // as an xml element attribute rather than an element.
      // We also provide an alternate name for the attribute.
      [XmlAttribute("firstName")]
      public string FirstName;
    
      [XmlAttribute("lastName")]
      public string LastName;
    
      [XmlElement("tel1")]
      public string PhoneNumber;
    
      [XmlElement("email")]
      public string EmailAddress;
    }
    

    Given the above, an instance of AddressBook serialized with an XmlSerializer would give XML of the following format

    <addressBook>
      <owner firstName="Chris" lastName="Taylor">
        <tel1>555-321343</tel1>
        <email>chris@guesswhere.com</email>
      </owner>
      <contact firstName="Natasha" lastName="Taylor">
        <tel1>555-321343</tel1>
        <email>natasha@guesswhere.com</email>
      </contact>
      <contact firstName="Gideon" lastName="Becking">
        <tel1>555-123423</tel1>
        <email>gideon@guesswhere.com</email>
      </contact>
    </addressBook>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between using the Runnable and Callable interfaces when designing a
What's the difference between using a define statement and an enum statement in C/C++
What is the difference between using a new thread and using a thread from
I see little functional difference between using a property public readonly property foo as
What is the difference between using system() to execute a binary and using the
Is there a difference between using a makefile and a Makefile?
What is the difference between using #include<filename> and #include<filename.h > in C++ ? Which
What is the difference between using ToString and ToString() in VB.NET?
What is the difference between using -agentlib:hprof=cpu=times vs -agentlib:hprof=cpu=sample when running a java class?
What is the difference between using Private Properties instead of Private Fields private String

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.