下面的代码片段序列化了一个类的简单实例
Person
到
<Person attribute="value" />
使用
IXmlSerializable
:
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
public class Person : IXmlSerializable
{
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader xmlReader)
{
throw new System.NotImplementedException();
}
public void WriteXml(XmlWriter xmlWriter)
{
xmlWriter.WriteAttributeString("attribute", "value");
}
}
class Program
{
public static void Main()
{
var xmlWriterSettings = new XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true
};
using (var xmlTextWriter = XmlWriter.Create(Console.Out, xmlWriterSettings))
{
var xmlSerializer = new XmlSerializer(typeof(Person));
var person = new Person();
xmlSerializer.Serialize(xmlTextWriter, person);
}
}
}
我正在寻找一种方法来修改
人
到
person
,我该怎么做?