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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:35:20+00:00 2026-05-11T06:35:20+00:00

If I have a class marked as a DataContract and a few properties on

  • 0

If I have a class marked as a DataContract and a few properties on it marked with DataMember attributes I can serialize it out to XML easily, but it would create output like:

<Person>     <Name>John Smith</Name>     <Email>john.smith@acme.com</Email>     <Phone>123-123-1234</Phone> </Person> 

What I would prefer is attributes, like…

<Person Name='John Smith' Email='john.smith@acme.com' Phone='123-123-1234' /> 

The DataMember attribute allows me to control the Name and Order but not whether it is serialized as an element or attribute. I have looked around and found DataContractFormat and IXmlSerializable but I am hoping there is there an easier solution.

What is the easiest way to do this?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T06:35:21+00:00Added an answer on May 11, 2026 at 6:35 am

    You can’t do this with the DataContractSerializer; if you want attributes you need to use the XmlSerializer instead. With the DataContractSerializer class a more restrictive subset of the XML specification is permitted which improves performance, and improves the interoperability of published services, but gives you rather less control over the XML format.

    If you’re using WCF services then take a look at XmlSerializerFormatAttribute which allows you to use the XmlSerializer for serialization.

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

Sidebar

Related Questions

I have a class that is marked with DataContract attributes and I would like
I have class and properties in there. Some properties can be marked attribute (it's
I have a .NET 2.0 class the properties of which are marked virtual.I need
Say I have a class with a few fields all marked with a custom
I'm mantaining some application and I have a class marked as Serializable but I
I have build chat service with WCF. I have class that marked as datacontract
I have class with its object properties marked internal. There is no accessibility issues
I have a class that doesn't extend webapp.RequestHandler , and I can't use self.response.out.write()
I have a class with a property marked with [XmlText] , that accepts multiline
I have a class in my C# project marked with the [Serializable] attribute. It

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.