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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:18:42+00:00 2026-05-11T08:18:42+00:00

Given the following XML: <?xml version=1.0?> <user_list> <user> <id>1</id> <name>Joe</name> </user> <user> <id>2</id> <name>John</name>

  • 0

Given the following XML:

<?xml version='1.0'?> <user_list>    <user>       <id>1</id>       <name>Joe</name>    </user>    <user>       <id>2</id>       <name>John</name>    </user> </user_list> 

And the following class:

public class User {    [XmlElement('id')]    public Int32 Id { get; set; }     [XmlElement('name')]    public String Name { get; set; } } 

Is it possible to use XmlSerializer to deserialize the xml into a List<User> ? If so, what type of additional attributes will I need to use, or what additional parameters do I need to use to construct the XmlSerializer instance?

An array ( User[] ) would be acceptable, if a bit less preferable.

  • 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. 2026-05-11T08:18:43+00:00Added an answer on May 11, 2026 at 8:18 am

    You can encapsulate the list trivially:

    using System; using System.Collections.Generic; using System.Xml.Serialization;  [XmlRoot('user_list')] public class UserList {     public UserList() {Items = new List<User>();}     [XmlElement('user')]     public List<User> Items {get;set;} } public class User {     [XmlElement('id')]     public Int32 Id { get; set; }      [XmlElement('name')]     public String Name { get; set; } }  static class Program {     static void Main()     {         XmlSerializer ser= new XmlSerializer(typeof(UserList));         UserList list = new UserList();         list.Items.Add(new User { Id = 1, Name = 'abc'});         list.Items.Add(new User { Id = 2, Name = 'def'});         list.Items.Add(new User { Id = 3, Name = 'ghi'});         ser.Serialize(Console.Out, list);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given the following XML 'template': <Request module=CRM call=list_service_features id={ID}> <block name=auth> <a name=username format=text>{USERNAME}</a>
Given the following XML: <?xml version=1.0 encoding=UTF-8?> <userAttributeList> <attribute> <userId>12345678</userId> <attId>1234</attId> <attName>Group</attName> <attTypeId>8</attTypeId> <attTypeName>User
Given the following XML <?xml version=1.0?> <Message> <ArrayOfStock xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Stock> <StockID>9cddb639-25ee-4415-be07-3109e5ae9883</StockID> <Description>Stock Item
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
Given the following XML: <databases> <database> <title_display>Aardvark</title_display> </database> <database> <title_display>Apple</title_display> </database> <database> <title_display>Blue</title_display> </database>
Consider the following XSLT script: <?xml version=1.0 encoding=ISO-8859-1?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=text encoding=iso-8859-1/>
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
Given the following Xml: <record> <category>Sport/Racket Sports/Tennis</category> <category>Sport/Racket Sports/Badminton</category> </record> I'm trying to break

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.