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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:45:37+00:00 2026-05-13T17:45:37+00:00

The problem is that I’ not getting the structure of XML that I want.

  • 0

The problem is that I’ not getting the structure of XML that I want. My Code is as follows:

[DataContract]
public class Persons
{
    [DataMember]
    public List<Person> Personas;
}

[DataContract]
public class Person
{
    [DataMember(Name="SSN")]
    public long SSN
    {
        get;
        set;
    }
    [DataMember(Name="Name")]
    public string Name
    {
        get;
        set;
    }

And when I run the DataContractSerializer the XML it returns is:

<Persons xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WCFTest">
 <Personas>
  <Person>
   <Name>B</Name>
   <SSN>1234</SSN>
  </Person>
  <Person>
   <Name>I</Name>
   <SSN>5678</SSN>
  </Person>
 </Personas>
</Persons>

I woul like to eliminate either element Persons or Personas, the root element should contain a list of Person.

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

    If you want the root element to be a list of Person, simply serialize the List instead of serializing Personas.

    DataContractSerializer ser =
                    new DataContractSerializer(typeof(List<Person>))
    ser.WriteObject(writer, persons.Personas)
    

    instead of

    DataContractSerializer ser =
                    new DataContractSerializer(typeof(Persons))
    ser.WriteObject(writer, persons)
    

    http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx

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

Sidebar

Related Questions

I recently have a problem that my java code works perfectly ok on my
I have a strange problem that I could not solve. When I try to
I have a problem that I have not managed to solve. I developed a
XML problem that's got me stumped, but is probably very simple... The XML is
I have a problem that I think is caused by the wm_keyup message not
My problem that I want to modify a style of a site with my
I have a small problem that I want to load a url in web
I am having the problem that I cannot select a specific XML node which
Simple problem that I can't figure out... How can I print a '%' character
The problem that I have is somehow very specific. I have to implement a

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.