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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:49:25+00:00 2026-05-25T01:49:25+00:00

I am trying to deserialize the following xml structure into an object… <?xml version=1.0

  • 0

I am trying to deserialize the following xml structure into an object…

<?xml version="1.0" encoding="utf-8"?>
<xmlRoot>
    <nest1>
        <element1>A</element1>
        <nest2>
            <element2>aqbc</element2>
            <element3>vjd</element3>
        </nest2>
    </nest1>
</xmlRoot>

There is no schema for it and i cannot alter it. now i am getting problems with putting this structure into class form….

Tthe only information i am interested in is the values of the elements inside nest2. My C# class looks like the following…

/// <summary>
/// Summary description for FirstResponse
/// </summary>
[Serializable]
[System.Xml.Serialization.XmlRoot("nest2")]
public class FirstResponse
{
    [System.Xml.Serialization.XmlElement("element2")]
    public string Element2{ get; set; }

    [System.Xml.Serialization.XmlElement("element3")]
    public string Element3{ get; set; }
}

Using the code below, I receive an exception or I just get a empty Object…

FirstResponse response = null;

    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(FirstResponse));
        StringReader reader = new StringReader(xmlString);

        response = (FirstResponse)serializer.Deserialize(reader);
        reader.Close();
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

    return response;

If i set the XmlRoot to ‘nest2’ i receive the exception; ‘ was not expected.’. If i change that value to ‘xmlRoot’ i get an empty object…

I am really not sure where i have gone wrong here….

  • 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-25T01:49:25+00:00Added an answer on May 25, 2026 at 1:49 am

    Two step process:

    1. take your XML and run xsd.exe (found in c:\Program Files\Microsoft SDKs\Windows\v7.0a\Bin – or c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0a\Bin on a x64 OS) on it:

      xsd.exe yourfile.xml
      

      This results in a XML schema file yourfile.xsd

    2. take that XSD file and run xsd.exe on it again, the the /c option:

      xsd.exe /c yourfile.xsd
      

      This results in a C# file yourfile.cs which represents a 1:1 mapping of your XML file structure into a C# class, which you should be able to use to deserialize that XML file into a C# 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 deserialize the following XML document: <?xml version=1.0 encoding=utf-8 ?> <TestPrice> <Price>
I'm trying to deserialize the following XML output: <?xml version=1.0 encoding=ISO-8859-1?> <Foo> <Val>Data1</Val> </Foo>
I am trying to de-serialize the following XML file. <?xml version=1.0 encoding=UTF-8?> <searchResult> <pagination>
I have the following xml I'd like to deserialize into a class <?xml version=1.0
I am trying to deserialize an object from XML in Ruby. Something simple like:
I'm trying to deserialize an xml structure that looks like this: <somecontainer> <key1>Value1</key1> <key1>Value2</key1>
I'm trying to use JSON.Net to deserialize a JSON object into a C# object.
I'm trying to deserialize the following XML (excerpt): <NSArray> <Song id=23507 type=Song> <title>Waking The
I get the following error when trying to deserialize an object in C#. Exception
I'm trying to persist an object into a MongoDB, using the following bit of

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.