Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add xsi:schemaLocation to serialized object

Tags:

c#

How can I add the following xsi:schemaLocation to a serialized class?

<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">

Here is what I have done so far:

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; }

}

When I deserialize the xml to the object in VS I get:

{"The method or operation is not implemented." There is an error in XML document (5, 44) - This actually points to the line: xsi:schemaLocation="http://ddex.net/xml/2010/ern-main/32 http://ddex.net/xml/2010/ern-main/32/ern-main.xsd"

like image 876
user1526912 Avatar asked Jan 23 '13 20:01

user1526912


1 Answers

Soultion:

[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string schemaLocation { get; set; }
like image 190
user1526912 Avatar answered Sep 18 '22 17:09

user1526912