XML to Class Object C#

<?xml version="1.0" encoding="UTF-16"?>
     <load entity="CUSTOMER" id="1234">
        <result-entry result-id="456" succeed="Yes">
           <return F_RESULT="focused" STATUS="C" />
        <result-entry result-id="789" succeed="No">
              <error name="other">
                      <error-message>Result cannot be validated</error-message>
     <load entity="CUSTOMER" id="5678">
        <result-entry result-id="789" succeed="Yes">
           <return F_RESULT="focused" STATUS="C" />
        <result-entry result-id="555" succeed="No">
              <error name="other">
                      <error-message>Result cannot be validated</error-message>

I want to return a class array of the following:
      Result-id's and succeed yes or no and if errors showing the error messages
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
You can use Generic serialization, I wrote sample signatures of such a class long back but it still works.

You can get more details from here: https://crmxpress.net/blog/2008/12/generic-serializer-deserializer/
public static T Deserialize<T>(
string serializedData
//check whether the incoming data is not a null string
if (string.IsNullOrEmpty(serializedData))
return default(T); //This can be controversial, so handle with care and as per your requirements, in certain cases you can return null as well, kindly let me know if you have anything that can improvise this code

//create a serializer
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
//Use the deserializer we have just created and deserialize the object.

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This is not valid XML. Is that a typo? (You're missing a closing </error> tag in a couple of places.)

Once you iron out the structure, you can use the XSD tool to generate a class file that matches this XML structure:

If you don't have an XSD file to start with, you can use the XSD tool to infer a schema from the XML. Just execute:

xsd.exe your.xml

The tool will output an XSD file of the same name (different extension). You can then pass that XSD into the tool as described in the linked article.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.