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

}

当我在vs中将xml反序列化为对象时,得到:
{“方法或操作未实现。”
XML文档中有一个错误(5,44)-这实际上指向一行:xsi:schemalocation=“http://ddex.net/xml/2010/ern-main/32http://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添加到序列化对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14488328/

10-12 05:18