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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:32+00:00 2026-06-18T08:32:32+00:00

Is there a C# library that allows mapping C# objects to XML without Attributes?

  • 0

Is there a C# library that allows mapping C# objects to XML without Attributes?

I have several data sources, all of them containing XML data with the same logical-structure, but different schema. For example in one XML there might be a field called ‘zip-code’, in another this data will be in attribute called ‘postal-code’ etc. I want to deserialize all XML sources in single C# class.

Obviously I can not use XMLAttrubtes, because there are different ‘paths’. I want something like EclipseLink MOXy (metadata is specified in XML), but for C#.

  • 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-18T08:32:33+00:00Added an answer on June 18, 2026 at 8:32 am

    The XmlSerializer allows you to specify attribute overrides dynamically at runtime. Let’s suppose that you have the following static class:

    public class Foo
    {
        public string Bar { get; set; }
    }
    

    and the following XML:

    <?xml version="1.0" encoding="utf-8" ?> 
    <foo bar="baz" />
    

    you could dynamically add the mapping at runtime without using any static attributes on your model class. Just like this:

    using System;
    using System.Xml;
    using System.Xml.Serialization;
    
    public class Foo
    {
        public string Bar { get; set; }
    }
    
    class Program
    {
        static void Main()
        {
            var overrides = new XmlAttributeOverrides();
            overrides.Add(typeof(Foo), new XmlAttributes { XmlRoot = new XmlRootAttribute("foo") });
            overrides.Add(typeof(Foo), "Bar", new XmlAttributes { XmlAttribute = new XmlAttributeAttribute("bar") });
            var serializer = new XmlSerializer(typeof(Foo), overrides);
            using (var reader = XmlReader.Create("test.xml"))
            {
                var foo = (Foo)serializer.Deserialize(reader);
                Console.WriteLine(foo.Bar);
            }
        }
    }
    

    Now all that’s left for you is to write some custom code that might read an XML file containing the attribute overrides and building an instance of XmlAttributeOverrides from it at runtime that you will feed to the XmlSerializer constructor.

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

Sidebar

Related Questions

Does Java have (or is there a library available) that allows me to have
Is there any library that allows to create a Carbon application using C++ classes?
Is there any java library that allows to export LaTeX document to other formats
Is there any library that allows to handle google talk messages using Ruby?
Is there a library that allows me to manipulate graphical components similar to Quartz
I know some languages have a library that allows you to get the HTTP
Is there a java library that allows me to update rather than recompute quantiles
Is there a .NET library that allows 3D transform of images? I want to
Is there a JavaScript library that allows to save strings as txt files, and
Is there a library for c# that allows me to build an encrypted token

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.