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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:34:11+00:00 2026-06-14T14:34:11+00:00

I need to create an object that can be deserialised from this XML <Item>

  • 0

I need to create an object that can be deserialised from this XML

  <Item>
    <Description>Timber(dry)</Description>
    <Measure Type="VOLUME">
      <Value>1.779</Value>
      <Units>m3</Units>
    </Measure>
    <Measure Type="WEIGHT">
      <Value>925.08</Value>
      <Units>Kilogram</Units>
    </Measure>
    <Measure>
      <Value>1</Value>
      <Units>Units</Units>
    </Measure>
  </Item>

My Problem is the Measure, it needs to be a list of some sort but when i create a
list it serialises incorrectly

  <Item>
    <Description>Timber(dry)</Description>
    <Measures>   <--- Dont want this <Measures> tag
     <Measure Type="VOLUME">
      <Value>1.779</Value>
      <Units>m3</Units>
     </Measure>
     <Measure Type="WEIGHT">
      <Value>925.08</Value>
      <Units>Kilogram</Units>
     </Measure>
     <Measure>
      <Value>1</Value>
      <Units>Units</Units>
     </Measure>
   </Measures> <--- 
  </Item>

This is what i have so far

public class Item
  {
    public Item()
    {
      this.Measures = new List<Measure>();
    }    

    public string Description { get; set; }

    public List<Measure> Measures { get; set; }
  }

  public class Measure
  {

    public string Value { get; set; }

    public string Units { get; set; }

    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Type { 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-14T14:34:12+00:00Added an answer on June 14, 2026 at 2:34 pm

    You need to decorate the Measures property with the [XmlElement] attribute, to indicate to the serializer that it needs to be serialized (and deserialized) as (bare) elements, instead of them being wrapped in another element.

    public class StackOverflow_13188624
    {
        const string XML = @"  <Item>
                                <Description>Timber(dry)</Description>
                                <Measure Type=""VOLUME"">
                                  <Value>1.779</Value>
                                  <Units>m3</Units>
                                </Measure>
                                <Measure Type=""WEIGHT"">
                                  <Value>925.08</Value>
                                  <Units>Kilogram</Units>
                                </Measure>
                                <Measure>
                                  <Value>1</Value>
                                  <Units>Units</Units>
                                </Measure>
                              </Item>";
    
        public class Item
        {
            public Item()
            {
                this.Measures = new List<Measure>();
            }
    
            public string Description { get; set; }
            [System.Xml.Serialization.XmlElement(ElementName = "Measure")]
            public List<Measure> Measures { get; set; }
        }
    
        public class Measure
        {
            public string Value { get; set; }
            public string Units { get; set; }
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string Type { get; set; }
        }
    
        public static void Test()
        {
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(XML));
            XmlSerializer xs = new XmlSerializer(typeof(Item));
            Item item = (Item)xs.Deserialize(ms);
            Console.WriteLine(item.Measures);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a class that will store a unique object elements. I
I have a need to create a library of Object Oriented PHP code that
I need to create interface MultiLingual, that allows to display object's data in different
I need to create an XML schema definition (XSD) that describes Java objects. I
i need to create a object Image from import javax.microedition.lcdui.Image; using a file .png
I need to create a List of object of whatever Enumeration type is passed
I have an object that can't be dumped by simplejson , so I need
This is the form file of django.contrib.comments.forms: https://github.com/django/django/blob/master/django/contrib/comments/forms.py I need to create an object
My JSON object that is returned from the server looks like this: [ {
I need a method that creates an empty clone of an object in 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.