gpt4 book ai didi

c# - 我想用命名空间序列化

转载 作者:太空宇宙 更新时间:2023-11-03 11:45:56 25 4
gpt4 key购买 nike

我想用 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; }
}

关于c# - 我想用命名空间序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3455541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com