我想用 C# 序列化 xml 中的以下结构。
<?xml version="1.0" encoding="UTF-8"?>
...
<complement>
<hello:world color="0" number="1" >
</complement>
...
... 或类似的东西。我对命名空间和属性序列化感兴趣:P
[(namespace)]
class { }
等等
谢谢
我想用 C# 序列化 xml 中的以下结构。
<?xml version="1.0" encoding="UTF-8"?>
...
<complement>
<hello:world color="0" number="1" >
</complement>
...
... 或类似的东西。我对命名空间和属性序列化感兴趣:P
[(namespace)]
class { }
等等
谢谢
您可以在各种 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; }
}