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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:32:52+00:00 2026-05-31T04:32:52+00:00

I’m using an XML based .config file for storing some records. My XML is

  • 0

I’m using an XML based .config file for storing some records. My XML is below:

    <?xml version="1.0" encoding="utf-8"?>
    <Data_List xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Configuration>
        <Name>1st Week</Name>
        <Binary>
          <Field>field1</Field>
          <Version>1.0</Version>
        </Binary>
        <Binary>
          <Field>field2</Field>
          <Version>2.0</Version>
        </Binary>
    </Configuration>
      <Configuration>
        <Name>2nd Week</Name>
        <Binary>
          <Field>field1</Field>
          <Version>2.0</Version>
        </Binary>
        <Binary>
          <Field>field2</Field>
          <Version>4.0</Version>
        </Binary>
    </Configuration>
</Data_List>

I’m using C# code as follows:

public Binary
{
public String Field;
public String Version;
}

public Configuration
{
public String Name;
public List<Binary> Binary_List = new List<Binary>();

public GetfromXML()
{
List<Configuration> lists = new List<Configuration>();
TextReader reader = new StreamReader("Data_List.config");
XmlSerializer serializer = new XmlSerializer(typeof(List<Configuration>));
lists=(List<Configuration>)serializer.Deserialize(reader);
reader.Close();
}

I’m getting an exception saying "There’s an error in XML document(2,2)". How can I fix it?

  • 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-31T04:32:54+00:00Added an answer on May 31, 2026 at 4:32 am

    I think the problem is that your model is not well structurized. In other words, serializer does not know how to read your .xml.

    Your xml is wrong. When you have List< T > there would be an:

        <ArrayOfT></ArrayOfT>
    

    in .XML. Here is how you need to do it!

    1. First, try using xml attributes from System.Xml.Serialization(i.e. [XmlArray()])

    2. It would be better that you use FileStream instead of just pointing out URI

       using(var filestream = new FileStream(//your uri, FIleMode.Open)
      {
      }
      
    3. Use properties instead of variables. Because later on you may want to bind.

    Example of my code how i managed to solve that issue:

    public ServiceMap Deserialize()
        {
            ServiceMap serviceMap = new ServiceMap();
    
            try
            {
                using (var fileStream = new FileStream(Settings.ServiceMapPath, FileMode.Open))
                {
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreComments = true;
    
                    using (XmlReader reader = XmlReader.Create(fileStream, settings))
                    {
                        serviceMap = _serializer.Deserialize(reader) as ServiceMap;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("File 'ServiceMap.xml' could not be found!");
            }
    
            return serviceMap;
        }
    

    My ServiceMap class:

        [XmlRoot("ServiceMap")]
    public class ServiceMap
    {
        [XmlArray("Nodes")]
        [XmlArrayItem("Node")]
        public List<Node> Nodes = new List<Node>();
    
        [XmlArray("Groups")]
        [XmlArrayItem("Group")]
        public List<Group> Groups = new List<Group>();
    
        [XmlArray("Categories")]
        [XmlArrayItem("Category")]
        public List<Category> Categories = new List<Category>();
    }
    

    EDIT: My XML:

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://   www.w3.org/2001/XMLSchema">
      <Nodes>
        <Node Name="Predrag">
      <Children>
        <Child>dijete1</Child>
        <Child>dijete2</Child>
        <Child>dijete3</Child>
        <Child>dijete4</Child>
      </Children>
      <Parents>
        <Parent>roditelj1</Parent>
        <Parent>roditelj2</Parent>
        <Parent>roditelj3</Parent>
      </Parents>
      <Group Name="Grupa" />
      <Category Name="Kategorija" />
    </Node>
    <Node Name="Tami">
      <Children>
        <Child>dijete1</Child>
        <Child>dijete2</Child>
      </Children>
      <Parents>
        <Parent>roditelj1</Parent>
      </Parents>
      <Group Name="Grupa2" />
      <Category Name="Kategorija2" />
    </Node>
    

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have just tried to save a simple *.rtf file with some websites and
In my XML file chapters tag has more chapter tag.i need to display chapters
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.