Попробуйте модуль iso8601 ; это делает точно это.
существует несколько других опций, упомянутых на страница WorkingWithTime на Wiki python.org.
Bare minimum working... looks like you are only required to add one attribute.
public class EmailConfiguration
{
public string DataBoxID { get; set; }
public DefaultSendToAddressCollectionClass DefaultSendToAddressCollection { get; set; }
}
public class DefaultSendToAddressCollectionClass
{
[XmlElement]
public string[] EmailAddress { get; set; }
}
Did you use VS2008's XSD?
Here's the output I got:
c:>xsd email.xml
Writing file 'c:\email.xsd'
c:>xsd email.xsd /c /edb
Writing file 'c:\email.cs'
Generates serializable output:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class EmailConfiguration : object, System.ComponentModel.INotifyPropertyChanged {
private string dataBoxIDField;
private EmailConfigurationDefaultSendToAddressCollection[] defaultSendToAddressCollectionField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string DataBoxID {
get {
return this.dataBoxIDField;
}
set {
this.dataBoxIDField = value;
this.RaisePropertyChanged("DataBoxID");
}
}
Использование .NET 3.5:
[XmlRoot]
public class EmailConfiguration
{
[XmlElement]
public string DataBoxID { get; set; }
[XmlElement]
public DefaultSendToAddressCollectionClass DefaultSendToAddressCollection { get; set; }
}
public class DefaultSendToAddressCollectionClass
{
[XmlElement]
public string[] EmailAddress { get; set; }
}
XSD.EXE is the tool that produces classes specifically for the purpose of XML Serialization. If it produces partial classes, that's because they work for XML Serialization. That's not what your problem is.
Try using XSD.EXE and serializing / deserializing. If you get an exception again, then please catch it and then post the results of ex.ToString().
Этот класс будет сериализован так, как вы хотите. Я изменил вашу пользовательскую коллекцию на список и использовал атрибут XmlArrayItem, чтобы указать, как каждый адрес электронной почты будет сериализован. Существует множество таких атрибутов, которые помогут вам точно настроить процесс сериализации.
[Serializable]
public class EmailConfiguration {
private string dataBoxID;
public string DataBoxID {
get { return dataBoxID; }
set { dataBoxID = value; }
}
private List<string> defaultSendToAddressCollection;
[XmlArrayItem("EmailAddress")]
public List<string> DefaultSendToAddressCollection {
get { return defaultSendToAddressCollection; }
set { defaultSendToAddressCollection = value; }
}
public EmailConfiguration() {
DefaultSendToAddressCollection = new List<string>();
}
}
XML serialization requires attributes. The way I've usually done it is to flag the class itself with [Serializable] and [XmlRoot], then mark up public properties with either [XmlElement], [XmlAttribute] or [NoSerialize].
What specific problem are you having?