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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:49:31+00:00 2026-05-25T14:49:31+00:00

I have a struct like this: public struct Vehicles { public string Name {

  • 0

I have a struct like this:

public struct Vehicles
{
    public string Name { get; set; }
    public string Count { get; set; }
    public List<Car> Cars { get; set; }
}

public struct Car
{
    public string Name { get; set; }
    public int Count { get; set; }
    public List<Tire> Tires { get; set; }
}

public struct Tire
{
    public string Brand { get; set; }
    public int Count { get; set; }
    public int UniqueCount { get; set; }
    public List<Dimension> Dimensions { get; set; }
}

public struct Dimension
{
    public string Size { get; set; }
    public int AlternateSize { get; set; }
}

When I serialize “Vehicles” it is like:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org /2001/XMLSchema">
  <Vehicles>
    <Name>SuperVehicles</Name>
    <Cars>
      <Car>
        <Name>BMW</Name>
        <Count>29</Count>
        <Tires>
          <Tire>
            <Name>DMZ</Name>
            <Count>26</Count>
            <UniqueCount>24</UniqueCount>
            <Dimensions>
              <Dimension>
                <Size>70x570</Size>
                <AlternateSize>70x580</AlternateSize>
              </Dimension>
              <Dimension>
                <Size>60x570</Size>
                <AlternateSize>60x580</AlternateSize>
              </Dimension>
              <Dimension>
                <Size>50x570</Size>
                <AlternateSize>50x580</AlternateSize>
              </Dimension>
            </Dimensions>
          </Tire>
        </Tires>
      </Car>
    </Cars>
  </Vehicles>
</root>

Now the problem is, I want to serialize it like this:

<root>
  <vehicles vehicleName="superVehicles" vehicleCount="50" carName="BMW"
      carCount="25" tireBrand="kamu" tireCount="15" tireUniqueCount="15"
      dimensionSize="70x570" dimensionAlternateSize="70x580" />
  <vehicles vehicleName="superVehicles" vehicleCount="35" carName="MERCEDES"
      carCount="22" tireBrand="kamu" tireCount="12" tireUniqueCount="12"
      dimensionSize="60x570" dimensionAlternateSize="60x580" />
  <vehicles vehicleName="superVehicles" vehicleCount="35" carName="PORSCHE"
      carCount="22" tireBrand="kamu" tireCount="12" tireUniqueCount="12"
      dimensionSize="60x570" dimensionAlternateSize="60x580" />
</root>

Do I have to change the structure and avoid the groupings or is there any way to create a schema for xml serialization to gather this result.

Summary:
I get all the child items in a new tag when I serialize the root struct to xml but I need to take them as properties of an instance that create only the count of root (Vehicles in this situation) element of rows to xml.

  • 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-25T14:49:31+00:00Added an answer on May 25, 2026 at 2:49 pm

    You need to do manual serialization.

    Here is how you can implement this using System.Xml.Linq :

    var xmlElementsVehicles  = new[]{
                                      new XElement("vehicles ", new object[]
                                      {
                                       new XElement("vehicleName", "superVehicles"),
                                       new XElement("vehicleCount", 35),
                                       new XElement("carName", "PORSCHE"),
                                       new XElement("carCount", 2)
                                      }),
                                      new XElement("vehicles ", new object[]
                                      {
                                       new XElement("vehicleName", "superVehicles"),
                                       new XElement("vehicleCount", 35),
                                       new XElement("carName", "PORSCHE"),
                                       new XElement("carCount", 2)
                                      })
                                    };
    var root = new XElement("root", xmlElementsVehicles );
    var myXml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), root);
    using (var xmlWriter = XmlWriter.Create(stream))
    {
      myXml.Save(xmlWriter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct like this: public struct MyStruct { public string Name; public
I have a struct like this: public struct stuff { public int ID; public
Suppose I have some simple struct like this: public struct WeightedInt { public int
I have defined my struct like this: struct Test { private string assayName; public
I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr {
Let's say I have a first structure like this: typedef struct { int ivalue;
Let's say I have a POCO like so: public class Name { public string
Given a struct like this: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty)
I have a struct more or less like this: [Serializable] [XmlRoot(Customer)] public struct TCustomer
I have a C++ struct that looks like this: struct unmanagedstruct { int flags;

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.