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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:13:59+00:00 2026-06-02T23:13:59+00:00

I’ve been reading these days about deserialization, DOM, LINQ to XML and LINQ to

  • 0

I’ve been reading these days about deserialization, DOM, LINQ to XML and LINQ to XSD… for a while, but as I am a newbie I don’t really get the whole picture so I’ll try to explain you my scenery:

I fetch an xml from another’s and I’m just trying to display the information that comes with it in an MVC project view.

I don’t really have an xsd so I reckon for deserializing it into an object I’ll have to use XSD tool for creating an scheme, then a class which matches this scheme and then populate this class and use it in a view. I think this can be done just with a sample xml, am I right?

Another option, is to create “my object” and populate it via DOM. I’ve done something similar lately (I posted a question about it) or even try some of the LINQ approaches (I’ve read the LINQ to XSD has been abandoned by Microsoft).

For the simple thing I’m trying to do I would go for the LINQ to XML but to be honest I haven’t understand fully all the differences I’ve read about the advantages and disadvantages of the different approaches so if someone could help me to decide I really appreciate it.

Thanks in advance

  • 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-02T23:14:01+00:00Added an answer on June 2, 2026 at 11:14 pm

    I’ll share the XMLManager we use in my current project. It’s really easy to use, you just pass in the Type of the object you want to serialze to and from, like this:

    YourObject myObject = new YourObject();
    myObject.SomeInfoString = "Hello World";
    XMLManager<YourObject>.SerialzeToFile(myObject, pathToSaveTo)
    
    YourObject loadedObject = XMLManager<YourObject>.SerialzeFromFile(pathToYourFile)
    

    Here’s the implementation (please note you might want to do something in the catch-clauses, I’ve removed what we do there because it’s specific to out implementation):

    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Reflection;
    using System.Xml;
    using System.Xml.Serialization;
    
    /// <summary>
    /// The XMLManager can be used to serialize to and from XML files.
    /// </summary>
    /// <typeparam name="T">The type to serialize.</typeparam>
    public static class XmlManager<T>
    {
        /// <summary>
        /// Static method SerializeFromFile
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <returns>
        /// returns T
        /// </returns>
        public static T SerializeFromFile(string path)
        {
            try
            {
                using (var xmlStream = new FileStream(path, FileMode.Open))
                {
                    return FromStream(xmlStream);
                }
            }
            catch (Exception ex)
            {
                return default(T);
            }
        }
    
        /// <summary>
        /// Method FromStream
        /// </summary>
        /// <param name="xmlStream">
        /// The xml stream.
        /// </param>
        /// <returns>
        /// returns T
        /// </returns>
        public static T FromStream(Stream xmlStream)
        {
            try
            {
                var xmlReader = XmlReader.Create(xmlStream);
                var serializer = new XmlSerializer(typeof(T));
    
                var value = (T)serializer.Deserialize(xmlReader);
                return value;
            }
            catch (Exception ex)
            {
                return default(T);
            }
        }
    
        /// <summary>
        /// Method SerializeToFile
        /// </summary>
        /// <param name="xmlObject">
        /// The xml object.
        /// </param>
        /// <param name="xmlPath">
        /// The xml path.
        /// </param>
        /// <param name="overwriteExisting">
        /// The overwrite existing.
        /// </param>
        public static void SerializeToFile(T xmlObject, string xmlPath, bool overwriteExisting)
        {
            try
            {
                var mode = overwriteExisting ? FileMode.Create : FileMode.CreateNew;
                using (var xmlStream = new FileStream(xmlPath, mode))
                {
                    ToStream(xmlObject, xmlStream);
                }
            }
            catch (Exception ex)
            {
            }
        }
    
        /// <summary>
        /// Method ToStream
        /// </summary>
        /// <param name="xmlObject">
        /// The xml object.
        /// </param>
        /// <param name="xmlStream">
        /// The xml stream.
        /// </param>
        public static void ToStream(T xmlObject, Stream xmlStream)
        {
            try
            {
                var xmlSettings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = false };
    
                var writer = XmlWriter.Create(xmlStream, xmlSettings);
                var serializer = new XmlSerializer(typeof(T));
    
                serializer.Serialize(writer, xmlObject);
            }
            catch (Exception ex)
            {
            }
        }
    }
    

    To pass this information to a view you make a property in the ViewModel of the object you’ve deserialized using the XMLManager, and bind it through XAML.

    public string MyObjectInfoString 
    {
        get
        {
            return this.myObject.InfoString;
        }
    
        set
        {
            if (this.myObject.InfoString == value)
            {
                return;
            }
    
            this.myObject.InfoString = value;
            RaisePropertyChanged("MyObjectInfoString");
        }
    }
    

    [Edit] Might as well show the XAML as well:

    <TextBlock Text="{Binding MyObjectInfoString}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.