简体   繁体   中英

<string xmlns=''> was not expected in c#

Hi all I am trying to serialize value in xml. Every time I am getting <string xmlns=''> was not expected in c# Not able to find root cause plz help me out here.

namespace CustomDataType.usercontrols
    {
        public partial class CustomDataTypes : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
        {
        private Status _umbval;
        public object value
        {
            get
            {
                var status = GetStatus();
                return SerializationHelper.ValueToXmlString(status);
            }
            set
            {
                //if (value == null || string.IsNullOrEmpty(value.ToString()))
                //{
                //    _umbval = Status.Empty;
                //}
                //else
                //{
                    _umbval   =(Status)SerializationHelper.ValueFromXmlString(value,typeof(Status));
                //}
            }
        }
    }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Xml.Serialization;

    namespace CustomDataType
    {
        [Serializable]
        [XmlRoot("StatuMain")]
        public class Status
        {
                [XmlElement("statusvalue")]
                public string StatusValue { get; set; }

                [XmlElement("statusvalue1")]
                public string StatusValue1 { get; set; }

                [XmlElement("statusvalue2")]
                public string StatusValue2 { get; set; }

                [XmlElement("statusvalue3")]
                public string StatusValue3 { get; set; }

                //[XmlElement("isEmailChecked")]
                //public bool HasEmailChecked { get; set; }

                //[XmlElement("datetime")]
                //public DateTime Date { get; set; }

                public static Status Empty 
                {
                    get
                    {
                        var schedule = new Status();
                        schedule = null;
                        return schedule;
                    }
                }
        }
    }

I think you should be using XmlNamespaceManager to set an empty namespace, instead of xmlns..

http://msdn.microsoft.com/en-us/library/d6730bwt(v=vs.80).aspx

XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("", "");
YourSeraializationMethod(reader);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM