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

  • Home
  • SEARCH
  • 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 6367975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:37:00+00:00 2026-05-25T00:37:00+00:00

We have XML generated from an external program that needs to be read into

  • 0

We have XML generated from an external program that needs to be read into our C# application.

I know we could use C# classes with [Serializable] tag to load the into objects but the problem is that we already have our object that is really more OO divised than the Xml. We do not want to have 2 sets of objects.

My though is that I could open the file with LinqToXml and fill up our objects. Is it okay to do it this way or the real best way is to use the [Serializable] tag with XmlElementAttribute and other tag into our OO model? (If the latest is the good solution, how can I put an attribute in object inside my object or to work with inheritance?).

Edit : Example

Let say that I have :

public class Movie {
    public string Name;
    public Actor LeadActor;
}

public class Actor {
    public string Name;
    public DateTime DOB;
}

And I want to serialize the Movie like this:

<Movie>
    <Name>Casino Royale</Name>
    <LeadActor>Daniel Craig</LeadActor>
</Movie>

The only way I see to make it works is to modify the Movie to have a LeadActor property that will concatenare the Actor property and make both Actor property with [XmlIgnore] attribute. But what if I do not want to alter those business object?

  • 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-25T00:37:00+00:00Added an answer on May 25, 2026 at 12:37 am

    If the structure of the xml data is known (and not too complex) I find using Xml.Linq the easiest way. Each class contains public static method to reconstruct itself from xml. You have to do it manually, but if the xml structure does not correspond to object structure that seems like the only way – and this one is quite simple.
    For your example it would be:

    public class Movie {
        public string Name;
        public Actor LeadActor;
        public static Movie FromXml (XElement x)
        {
            Movie m = new Movie();
            m.Name = x.Element("Name").Value;
            m.LeadActor = Actor.FromXml(x.Element("LeadActor"));
            return m;
        }
    }
    
    public class Actor {
        public string Name;
        public DateTime DOB;
        public static Actor FromXml (XElement x)
        {
            Actor a = new Actor();
            a.Name = x.Value;
            a.DOB = ... 
            return a;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document generated from an external application, but that application does
I have to load some XML data (generated from a database, using PHP) into
I have a T4 template that generates classes from an xml file. How can
I have an automatically generated XML file for the game that I run. It
When developing an application which consumes an external webservice I have generated the sources
I know it is easier to read xml files in vb.net but since our
I'm new to LINQ and C# but I have an xml file generated from
I have a Java string of XML content. I use Velocity to generate some
I have xml files I want to read in and store in the database.
I have XML files in a directory that I wish to get over to

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.