我想用C#在xml中序列化以下结构。
<?xml version="1.0" encoding="UTF-8"?>
...
<complement>
<hello:world color="0" number="1" >
</complement>
...
......或类似的东西。我对名称空间和属性序列化感兴趣:P
[(namespace)]
class { }
等
由于
答案 0 :(得分:2)
您可以在各种XML序列化属性中指定名称空间。这是一个示例:
[XmlRoot(Namespace = "http://schemas.fabrikam.com/mynamespace")]
[XmlType(Namespace = "http://schemas.fabrikam.com/mynamespace")]
public class MyObject
{
[XmlElement(Namespace = "http://schemas.fabrikam.com/anothernamespace")]
public string MyElement { get; set; }
[XmlAttribute(Namespace = "http://schemas.fabrikam.com/yetanothernamespace")]
public string MyAttribute { get; set; }
}