輸入...注意,註釋是由xsd工具生成的代碼。這是在31,834線文件和專有,但我在這裏粗略近似。XMLSerializer未序列化DateTime
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class comment
{
private System.DateTime commentDateField;
private bool commentDateFieldSpecified;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public System.DateTime commentDate
{
get
{
return this.commentDateField;
}
set
{
this.commentDateField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool commentDateSpecified
{
get
{
return this.commentDateFieldSpecified;
}
set
{
this.commentDateFieldSpecified = value;
}
}
//other fields omitted for clarity
}
comment c = new comment();
c.text = txtComment.Text;
c.commentDate = DateTime.Now;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlSerializer xs = new XmlSerializer(typeof(comment));
xs.serialize(sw as TextWriter, c);
string output = sb.ToString();
輸出 - >
<comment>
<text>My Comment Text</text>
</comment>
在哪裏約會?
我們可以看到關於這兩個屬性你'Comment'類的定義? – 2010-01-08 20:16:23
我們需要看到註釋類的定義。 – 2010-01-08 20:18:46
順便說一句,你缺少一些使用條款 – empi 2010-01-08 20:21:12