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

The Archive Base Latest Questions

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

I am trying to define C# objects based on this XML: <UPDs LUPD=86> <UPD

  • 0

I am trying to define C# objects based on this XML:

<UPDs LUPD="86">
  <UPD ID="106">
    <ER R="CREn">
      <NU UID="1928456" />
      <NU UID="1886294" />
      <M>
        <uN>bob · </uN>
        <mO>fine :D</mO>
      </M>

So far I have:

public class UDPCollection    
{
    List<UDP> UDPs; 

    public UDPCollection()
    {
        UDPs = new List<UDP>();
    }
}

public class UDP
{
    public int Id;
    public List<ER> ERs;
    public UDP(int id, List<ER> ers)
    {
        Id = id;
        ERs = ers;
    }
}

public class ER
{
    public string LanguageR;

    public ER(string languager)
    {
        LanguageR = languager;
    }
}

My questions: What do elements map to in C#? Classes? What do attributes map to? Properties? Am I going about this the correct way?

  • 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-11T04:14:30+00:00Added an answer on June 11, 2026 at 4:14 am

    Use the XmlSerializer class and the XmlRoot, XmlElement and XmlAttribute attributes. For example:

    using System.Xml.Serialization;
    
    ...
    
    [XmlRoot("UPDs")]
    public class UDPCollection
    {
        // XmlSerializer cannot serialize List. Changed to array.
        [XmlElement("UPD")]
        public UDP[] UDPs { get; set; }
    
        [XmlAttribute("LUPD")]
        public int LUPD { get; set; } 
    
        public UDPCollection()
        {
            // Do nothing
        }
    }
    
    [XmlRoot("UPD")]
    public class UDP
    {
        [XmlAttribute("ID")]
        public int Id { get; set; }
    
        [XmlElement("ER")]
    
        public ER[] ERs { get; set; }
    
        // Need a parameterless or default constructor.
        // for serialization. Other constructors are
        // unaffected.
        public UDP()
        {
        }
    
        // Rest of class
    }
    
    [XmlRoot("ER")]
    public class ER
    {
        [XmlAttribute("R")]
        public string LanguageR { get; set; }
    
        // Need a parameterless or default constructor.
        // for serialization. Other constructors are
        // unaffected.
        public ER()
        {
        }
    
        // Rest of class
    }
    

    The code to write out the XML is:

    using System.Xml.Serialization;
    
    ...
    
    // Output the XML to this stream
    Stream stream;
    
    // Create a test object
    UDPCollection udpCollection = new UDPCollection();
    udpCollection.LUPD = 86;
    udpCollection.UDPs = new []
    {
        new UDP() { Id= 106, ERs = new [] { new ER() { LanguageR = "CREn" }}}
    };
    
    // Serialize the object
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(UDPCollection));
    xmlSerializer.Serialize(stream, udpCollection);
    

    Not that the XmlSerializer adds additional namepsaces but it can parse XML without them if needed. The output of the above is:

    <?xml version="1.0"?>
    <UPDs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" LUPD="86">
        <UPD ID="106">
           <ER R="CREn" />
        </UPD>
    </UPDs>
    

    Use the Deserialize() method to parse it from XML into an object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to define functions on a object within a prototype like in this
I am trying to define a number of classes based on an abstract base
I am trying to marshall data within an object into an xml file based
Im trying to define a select tag in my view. My view looks like
I'm trying to define a method in my vb.net interface that will only accept
I am trying to define a dynamic var in a different namespace. The Lobos
I am trying to define an abstract class that has operators to compare two
I'm trying to define a very simple function in Drools as below: import java.util.List;
I am trying to define nested modules, but I couldn't find any complete explanations
I'm trying to define a service endpoint in my web.config file so that I

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.