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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:50+00:00 2026-05-23T10:48:50+00:00

I need to serialize an Object to XML and back. The XML is fix

  • 0

I need to serialize an Object to XML and back. The XML is fix and I can’t change it.
I fail to generate this structure after bookingList.

How can I “group” these <booking> elements to appear as a LIST and keep <error> & <counter> before this List of <booking> elements.

See my example here:

Structure i need….

<nicexml>
<key_id>1234567</key_id>
<surname>Jil</surname>
<name>Sander</name>
<station_id>1</station_id>
<ownBookings>
    <bookingList>
        <error></error>
        <counter>20</counter>
        <booking>
             <bookingID>1234567890</bookingID>
        </booking>
        <booking>
             <bookingID>2345678901</bookingID>
        </booking>
    </bookingList>
</ownBookings>
</nicexml>

Structure i get with C# code below….

<nicexml>
<key_id>1234567</key_id>
<surname>Jil</surname>
<name>Sander</name>
<station_id>1</station_id>
<ownBookings>
    <bookingList>
           <booking>
        <booking>
             <bookingID>1234567890</bookingID>
        </booking>
        <booking>
             <bookingID>2345678901</bookingID>
        </booking>
             <booking>
        <error></error>
        <counter>20</counter>
    </bookingList>
</ownBookings>
</nicexml>

C# Code:

using System;
using System.Xml.Serialization;
using System.Collections.Generic;

namespace xml_objects_serials
{
    public class bookings
    {
        public class nicexml
        {
            public string key_id
            { get; set; }

            public string surname
            { get; set; }

            public string name
            { get; set; }

            public int station_id
            { get; set; }

            public ownBookings ownBookings
            { get; set; }

        }

        public class ownBookings
        {
            public bookingList bookingList
            { get; set; }

        }
        public class bookingList {
            public string error 
            { get; set; }
            public int counter
            { get; set; }
            public List<booking> booking= new List<booking>();
        }

        public class booking
        {
            public int bookingID
            { 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-05-23T10:48:50+00:00Added an answer on May 23, 2026 at 10:48 am

    Try decorating the properties of the bookingListclass with the XmlElementAttribute, in order to control how the objects of that class are going to be serialized to XML.

    Here’s an example:

    public class bookingList
    {
        [XmlElement(Order = 1)]
        public string error { get; set; }
        [XmlElement(Order = 2)]
        public int counter { get; set; }
        [XmlElement(ElementName = "booking", Order = 3)]
        public List<booking> bookings = new List<booking>();
    }
    
    public class booking
    {
        public int id { get; set; }
    }
    

    In my test I obtained this output:

    <?xml version="1.0" ?> 
    <bookingList>
        <error>sample</error>
        <counter>0</counter>
        <booking>
            <id>1</id> 
        </booking>
        <booking>
            <id>2</id> 
        </booking>
        <booking>
            <id>3</id> 
        </booking> 
    </bookingList>
    

    Related resources:

    • Controlling XML Serialization Using Attributes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object graph that I need to serialize to xml and save
I need to serialize an XML java object to a XML file using the
I'm in need to serialize an string that is valid xml to an object.
I am using an XmlSerializer to serialize an object to xml. After the object
I need to serialize an object like this: public class Book { public string
I need to read and serialize objects from and to XML, Apple's .plist format
I have a business class which I need to serialize to xml. It has
I'm tryng to serialize an object to XML by using C# with the following
Microsoft provides code in its article, How to serialize an object to XML by
Here is the structure of the data my object will need to expose (the

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.