c# - 如何添加xsi :schemaLocation to serialized object

标签 c#

如何将以下 xsi:schemaLocation 添加到序列化类中?

<ern:NewReleaseMessage xmlns:ern="http://ddex.net/xml/2010/ern-main/32"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       LanguageAndScriptCode="en"
                       xsi:schemaLocation="http://ddex.net/xml/2010/ern-main/32 http://ddex.net/xml/2010/ern-main/32/ern-main.xsd"
                       MessageSchemaVersionId="2010/ern-main/32">

这是我到目前为止所做的:

public class NewReleaseMessage
{
    [XmlAttribute]
    public string LanguageAndScriptCode { get; set; }

    [XmlAttribute("schemaLocation", Namespace = "http://ddex.net/xml/2010/ern-main/32")] 
    public string  schemaLocation = "http://ddex.net/xml/2010/ern-main/32 http://ddex.net/xml/2010/ern-main/32/ern-main.xsd";

    [XmlAttribute]
    public string MessageSchemaVersionId { get; set; }

    [XmlElement()]
    public MessageHeader MessageHeader { get; set; }

}

当我将 xml 反序列化为 VS 中的对象时,我得到:

{“该方法或操作未实现。” XML 文档中存在错误 (5, 44) - 这实际上指向以下行:xsi:schemaLocation="http://ddex.net/xml/2010/ern-main/32 http://ddex.net/xml/2010/ern-main/32/ern-main.xsd "

最佳答案

灵魂:

[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string schemaLocation { get; set; }

关于c# - 如何添加xsi :schemaLocation to serialized object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14488328/

相关文章:

c# - 避免将“转换为”

c# - 无法等待进程运行直到结束

c# - 如何在mysql中的两个表中取两个总和的差

c# - ASP.NET MVC 核心 POST 请求不将 JSON 数据转换为模型

c# - 如何从 tableAdapter 获取数据

c# - AsOrdered() 不起作用

c# - 为什么 nservicebus 忽略我的订阅消息?

c# - 从 FHIR 模式生成 C# 类

c# - NLog:如何在内部布局中包含静态字符

c# - asp.net core 中的 app.RunIISPipeline() 需要哪些引用资料?