大家好我想在xml中序列化值。每次我收到<string xmlns=''>
都不会在c#中找不到根本原因plz帮助我。
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;
}
}
}
}
答案 0 :(得分:3)
我认为你应该使用XmlNamespaceManager来设置一个空命名空间,而不是xmlns ..
http://msdn.microsoft.com/en-us/library/d6730bwt(v=vs.80).aspx
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("", "");
YourSeraializationMethod(reader);