7

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

4

2 回答 2

9

灵魂:

[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string schemaLocation { get; set; }
于 2013-01-23T23:43:24.973 回答
0

以下是对我有用的:

注意:“XmlAttributeAttribute”

[XmlAttributeAttribute(AttributeName = "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";
于 2020-07-29T09:24:01.500 回答