C# - What is http://schemas.datacontract.org/2004/07/ ?

The string http://schemas.datacontract.org/2004/07/ is the default namespace URI prefix for a DataContract class.

When you decorate a class with the DataContract attribute, the class becomes part of a data contract -- a formal specification of a type that can be shared between cooperating systems.

A DataContract class has a name and a namespace URI.

By default, the name is the name of the class, and namespace URI is formed form the default namespace URI prefix and the namespace of the class. This behaviour can be changed.

For example: the class below generates the following XML when serialized. The class name is President, and the namespace URI is formed from the default namespace URI prefix, and the namespace of the class. I.e. xmlns="http://schemas.datacontract.org/2004/07/Zuga.net"

namespace Zuga.net
{
    [DataContract]
    public class President
    {
        [DataMember] public int Number { get; set; }
        [DataMember] public string First { get; set; }
        [DataMember] public string Last { get; set; }
        [DataMember] public int Year { get; set; }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<President xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Zuga.net">
    <First>George</First>
    <Last>Washington</Last>
    <Number>1</Number>
    <Year>1789</Year>
</President>

Ads by Google


Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath