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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:02:26+00:00 2026-06-16T03:02:26+00:00

I do a de-serialization of a XML file which is something like: <?xml version=1.1

  • 0

I do a de-serialization of a XML file which is something like:

  <?xml version="1.1" ?>
  <Veggies>
       <Carrot>
             <quantity> 1 </quantity>
       </Carrot>
  </Veggies>

Ok. I write classes like

[Serializable]
public class Veggies
{
    [XmlRoot("Veggies")]
    public Carrot carrot;
}

[Serializable]
public class Carrot
{
   [XmlElement("Quantity")]
   public string Quantity;
}

All is well.

But if someone parses an input file which is something like below,

  <?xml version="1.1" ?>
  <Figs>
      <quantity> 11 </quantity>
  </Figs>
  <Veggies>
       <Carrot>
             <quantity> 1 </quantity>
       </Carrot>
  </Veggies>

I get an error.
Could you please suggest me a solution so that the Quantity of carrot can alone be retrieved leaving the other data but throwing no errors ?

Thanks.

  • 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-16T03:02:27+00:00Added an answer on June 16, 2026 at 3:02 am

    Ok guyz.. I figured myself out!

    <?xml version="1.1" ?>
    <Figs>
      <quantity> 11 </quantity>
    </Figs>
    <Veggies>
        <Carrot>
              <quantity> 1 </quantity>
        </Carrot>
    </Veggies>
    

    is not allowed because it does not respect the rule that “All Elements should be inside the RootElement tag.”

    If the file had been something like,

    <?xml version="1.1" ?>
    <Veggies>
        <Figs>
            <quantity> 11 </quantity>
        </Figs>
        <Carrot>
            <quantity> 1 </quantity>
        </Carrot>
    </Veggies>
    

    Then the quantity of the carrot can alone be read and others don’t exactly throw any errors.

    So, “Always put the elements inside a rootElement (here in example, “Veggies”)” or in other words, the elements should obey the de-serialization class structures.

    Thanks.

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

Sidebar

Related Questions

I imagine to use XML serialization like this: class Foo { public Foo (string
When using XML serialization in C#, I use code like this: public MyObject LoadData()
I'm trying to build an object that looks something like this: public class MyObject
I have a VB.NET class which I'm serializing via XML in an asmx file.
My application loads an XML data set from a file on disk using serialization,
I am using xml serialization and de-serialization to read and write to an XML
Related: How can I use polymorphism in XML Serialization? I have a class I
i have another question on getting my XML serialization neat, which i can't seem
I'm using serialization and deserialization in C# for my Project (which is a Class).
I'm deserialising an XML file which comes from a webservice of one of our

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.