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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:23:08+00:00 2026-06-10T07:23:08+00:00

lookin my XML example, how I do to Deserialize it? But I need to

  • 0

lookin my XML example, how I do to Deserialize it?
But I need to Deserialize the Xml Element array. How I do it?

<hotels num="1">
<hotel num="1" item="2"></hotel>
<hotel num="2" item="2"></hotel>
<hotel num="3" item="2"></hotel>
<hotel num="4" item="2"></hotel>
<hotel num="5" item="2"></hotel>
</hotels>

[Serializable]
[XmlRoot("hotels")]
public class Hotels
{
[XmlElement("id")]
public string id {  get; set; }
[XmlElement("hotel")]
public Hotel hotel { get; set; }
}

[Serializable]
[XmlRoot("hotel")]
public class Hotel
{
[XmlElement("id")]
public string id {  get; set; }
[XmlElement("item")]
public string item {  get; set; }
}
  • 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-06-10T07:23:09+00:00Added an answer on June 10, 2026 at 7:23 am

    Try like this:

    [XmlRoot("hotels")]
    public class HotelData
    {
        [XmlAttribute("num")]
        public string Id { get; set; }
    
        [XmlElement("hotel")]
        public List<Hotel> Hotels { get; set; }
    }
    
    public class Hotel
    {
        [XmlAttribute("num")]
        public string Id { get; set; }
    
        [XmlAttribute("item")]
        public string Item { get; set; }
    }
    

    and then deserialize:

    public class Program
    {
        static void Main()
        {
            var serializer = new XmlSerializer(typeof(HotelData));
            using (var reader = XmlReader.Create("test.xml"))
            {
                var data = (HotelData)serializer.Deserialize(reader);
                Console.WriteLine(data.Id);
                foreach (var hotel in data.Hotels)
                {
                    Console.WriteLine("num: {0}, item:{1}", hotel.Id, hotel.Item);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is an example XML (case 1) : <root> <Item> <ItemID>4504216603</ItemID> <ListingDetails> <StartTime>10:00:10.000Z</StartTime> <EndTime>10:00:30.000Z</EndTime>
I have an example XML like this: <rss version=2.0> <channel> <title></title> <link></link> <description></description> <item>
Looking to nest (to unlimited levels) elements in XML. Like so: <items> <item> <name>Item
It it possible for objective c to compile xml data (aiml files for example)??
I m looking for some good example of reading a well-formed and valid xml
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
I tried looking for what I need but I did so unsuccessfully. I am
Take the following 4 example XML documents: <Example> <Colour>orange</Colour> </Example> <Example> <Car colour=orange>Ford Focus</Car>
I'm using AJAX to receive an XML response, which I then need to manipulate.
Looking for readable example use of Omni Xml package. the documentation now is 2

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.