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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:52:41+00:00 2026-06-16T21:52:41+00:00

I have following XML file format. I want to deserialize following into object, but

  • 0

I have following XML file format. I want to deserialize following into object, but it does not work. I get problem while deserializing “Field”.

<ExportDefinition>
  <DestinationDir>C:\Export\</DestinationDir>
  <LevelID>102</LevelID>
  <Metadata>
    <Field>
        <Source>CreateDate</Source>
        <DataType>DateTime</DataType>
    <Field>
    <Field>
        <Source>UserName</Source>
        <DataType>Text</DataType>
    <Field>
  </Metadata>
</ExportDefinition>



static void Main(string[] args)
{
   string xmlFile = @"C:\cobra_exp_def.xml";
   FileStream ReadFileStream = new FileStream(xmlFile, FileMode.Open, FileAccess.Read, FileShare.Read);

  XmlSerializer SerializerObj = new XmlSerializer(typeof(ExportDefinition));
  ExportDefinition LoadedObj = (ExportDefinition)SerializerObj.Deserialize(ReadFileStream);

  ReadFileStream.Close();
}

public class ExportDefinition
{
   [XmlElement]
   public string DestinationDir { get; set; }

   [XmlElement]
   public string LevelID { get; set; }
}

public class Metadata
{
   private List<Field> list = new List<Field>();

   [XmlElement]
   public List<Field> Metadata { get { return list; } set { list = value; } }
}

public class Field
{
  [XmlElement]
  public string Source { get; set; }

  [XmlElement]
  public string DataType { get; set; }
}

Solution


Finally have managed it to work with following:

[XmlArray("Metadata"), XmlArrayItem("Field", typeof(Field))]
        public List<Field> Metadata
        {
            get { return (_fields); }
            set { _fields = value; }
        } 

        private List<Field> _fields = new List<Field>();
  • 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-16T21:52:42+00:00Added an answer on June 16, 2026 at 9:52 pm

    The InnerException is:

    “The ‘Field’ start tag on line 12 position 12 does not match the end tag of ‘Metadata’. Line 13, position 5.”

    Which is entirely correct; the xml is invalid. It should be:

    <Field>
        <Source>CreateDate</Source>
        <DataType>DateTime</DataType>
    </Field>  <!-- EDITED HERE -->
    <Field>
        <Source>UserName</Source>
        <DataType>Text</DataType>
    </Field>  <!-- EDITED HERE -->
    

    Always look at the InnerException. And if that has an InnerException, look at that too.

    You’ll also need to add a Metadata property to ExportDefinition, and use EmlElement("Field")] on the list property inside Metadata.

    Or more simply, remove the Metadata class completely:

    public class ExportDefinition
    {
       [XmlElement]
       public string DestinationDir { get; set; }
    
       [XmlElement]
       public string LevelID { get; set; }
    
       private List<Field> list = new List<Field>();
    
       [XmlArray("Metadata")]
       [XmlArrayItem("Field")]
       public List<Field> Items { get { return list; } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file in the following format: <food> <desert> cake <desert> </food>
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have created an XML file in the following format: <?xml version=1.0 encoding=utf-8 ?>
If suppose I have the following XML file in the following format: <Employee> <EmpInfo>
I have the following XML file containing letter and word definitions in this format
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have the following XML File: <persons> <person name=shawn> <age>34</age> <hair style=spikes>red</hair> </person> <person
I have the following XML file:- <?xml version=1.0 encoding=UTF-8?> <viewentries> <viewentry position=1> <entrydata columnnumber=0>
I have the following xml file: <xfa:data> <form1> <Page1> <Page2> <contractInfo> ... </contractInfo> <paymentInfo>
I have the following XML layout file, HELPME.XML <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent

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.