// 需要序列化的对象
[XmlRoot(ElementName ="interface",Namespace ="")]
public class Root
{
[XmlAttribute("schemaLocation",Namespace= XmlSchema.InstanceNamespace)]
public string xsiSchemaLocation = "http://wwww.test.com";
[XmlAttribute(AttributeName ="version")]
public string Version { get; set; }
}
// 序列化方法
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms, Encoding.UTF8);
XmlSerializer serializer = new XmlSerializer(typeof(Root));
serializer.Serialize(sw,root);
result = Encoding.UTF8.GetString(ms.GetBuffer());
sw.Close();
ms.Close();
//序列化结果
<?xml version="1.0" encoding="utf-8"?>
<interface xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wwww.test.com" version="测试版本">
<globalInfo>
<InterfaceCode>2</InterfaceCode>
</globalInfo>
</interface>
我想要在中显示,该如何设置?