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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:50:21+00:00 2026-05-27T08:50:21+00:00

I have a problem with deserialization of my xml files. Let’s pretend that we

  • 0

I have a problem with deserialization of my xml files. Let’s pretend that
we have a xml file and a class that we are using for deserialization to.

For example:

xml –

<dataStore>
  <name>newDataStore1</name>
  <description>sdffasdfasdf</description>
  <type>Shapefile</type>
  <enabled>false</enabled>
  <workspace>
    <name>newTestWorkspace</name>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="ht
tp://192.168.6.71:8080/geoserver/rest/workspaces/newTestWorkspace.xml" type="app
lication/xml"/>
  </workspace>
  <connectionParameters>
    <entry key="memory mapped buffer">false</entry>
    <entry key="create spatial index">true</entry>
    <entry key="charset">ISO-8859-1</entry>
    <entry key="filetype">shapefile</entry>
    <entry key="cache and reuse memory maps">true</entry>
    <entry key="url">file:data/shapefiles/states.shp</entry>
    <entry key="namespace">http://www.opengeospatial.net/cite</entry>
  </connectionParameters>
  <__default>false</__default>
  <featureTypes>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="ht
tp://192.168.6.71:8080/geoserver/rest/workspaces/newTestWorkspace/datastores/new
DataStore1/featuretypes.xml" type="application/xml"/>
  </featureTypes>
</dataStore>

Class

namespace GeoServerApiTester
{


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlRootAttribute("dataStore", Namespace="", IsNullable=false)]
    public partial class DataStore
    {

        private string nameField;

        private string typeField;

        private bool enabledField;

        private WorkSpacePreview workspaceField;

        private ConnectionParametersStorageEntryCollection connectionParametersField;

        private string @__defaultField;

        private LinkCollection featureTypesField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0, ElementName="name")]
        public string Name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1, ElementName="type")]
        public string Type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2, ElementName="enabled")]
        public bool Enabled
        {
            get
            {
                return this.enabledField;
            }
            set
            {
                this.enabledField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=3, ElementName="workspace")]
        public WorkSpacePreview Workspace
        {
            get
            {
                return this.workspaceField;
            }
            set
            {
                this.workspaceField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order=4, ElementName="connectionParameters")]
        [System.Xml.Serialization.XmlArrayItemAttribute("entry", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public ConnectionParametersStorageEntryCollection ConnectionParameters
        {
            get
            {
                return this.connectionParametersField;
            }
            set
            {
                this.connectionParametersField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
        public string @__default
        {
            get
            {
                return this.@__defaultField;
            }
            set
            {
                this.@__defaultField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order=6, ElementName="featureTypes")]
        [System.Xml.Serialization.XmlArrayItemAttribute("link", Namespace="http://www.w3.org/2005/Atom", IsNullable=false)]
        public LinkCollection FeatureTypes
        {
            get
            {
                return this.featureTypesField;
            }
            set
            {
                this.featureTypesField = value;
            }
        }

        public virtual bool ShouldSerializeConnectionParameters()
        {
            return ((this.ConnectionParameters != null) 
                        && (this.ConnectionParameters.Count > 0));
        }

        public virtual bool ShouldSerializeFeatureTypes()
        {
            return ((this.FeatureTypes != null) 
                        && (this.FeatureTypes.Count > 0));
        }
    }
}

You can see that the class doesn’t contain description field.

<dataStore>
  <name>newDataStore1</name>
  <enabled>false</enabled>
</dataStore>

You can see that all elements after description were not be deserialized.

When program gets xml content and this xml contains an element that isn’t in the class all elements after this element won’t be desirialized.

How can I skip unknown element during deserialization and get something like this:

<dataStore>
  <name>newDataStore1</name>

  <type>Shapefile</type>
  <enabled>false</enabled>
  <workspace>
    <name>newTestWorkspace</name>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="ht
tp://192.168.6.71:8080/geoserver/rest/workspaces/newTestWorkspace.xml" type="app
lication/xml"/>
  </workspace>
  <connectionParameters>
    <entry key="memory mapped buffer">false</entry>
    <entry key="create spatial index">true</entry>
    <entry key="charset">ISO-8859-1</entry>
    <entry key="filetype">shapefile</entry>
    <entry key="cache and reuse memory maps">true</entry>
    <entry key="url">file:data/shapefiles/states.shp</entry>
    <entry key="namespace">http://www.opengeospatial.net/cite</entry>
  </connectionParameters>
  <__default>false</__default>
  <featureTypes>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="ht
tp://192.168.6.71:8080/geoserver/rest/workspaces/newTestWorkspace/datastores/new
DataStore1/featuretypes.xml" type="application/xml"/>
  </featureTypes>
</dataStore>

remove only element

  • 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-27T08:50:21+00:00Added an answer on May 27, 2026 at 8:50 am

    By default the XmlSerializer ignores unknown nodes (so elements as well). Now when you use the Order property like you do, you are telling explicitly in which Order to serialize/deserialize.

    So when the XmlSerializer comes to your description element this becomes a unknown element because it expects the type element. The rest will also be threated as unknown elements because they do not map anymore to your specified order. For example when it comes to your type element which has index two in your XML, it expects it be the enabled element so this element becomes unknown as well.

    You can check this behaviour by handling the UnknownNode event of the XmlSerializer class. This event will be fired for every unknown node it encounters.

    How to proceed? If the ordering has no meaning don’t use it. There are situations where it does make sense to use ordering. A classical example I’ve seen multiple times are (legacy) apps which treat XML documents as strings and read all the elements from top to bottom.

    Another option would be implementing the IXmlSerializer interface, which gives you better control on how your object is serialized and deserialized.

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

Sidebar

Related Questions

I have a problem with deserialization in my silverlight project. I have class Obj
I have a deserialization method (XML) that functions well until it gets to X
I have problems during serialization/deserialization. I'm using a WCF service (that used .NET framework)
I have a class I serialize to a file, ie. myfile01.myfile. I'm using binary
I have an XML file that has data in it, but one of the
I have problem in some JavaScript that I am writing where the Switch statement
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I have the problem when sequentially serialize-deserialize-serialize a TestClass: [Serializable] public class TestClass {
PROBLEM: I have a Child class which uses DataContractSerialization and raises a Changed event

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.