gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:13:56 25 4
gpt4 key购买 nike

如何将以下 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/

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