Controls the XML schema generated when the attribute target is serialized by the XmlSerializer.
For a list of all members of this type, see XmlTypeAttribute Members.
System.Object
System.Attribute
System.Xml.Serialization.XmlTypeAttribute
[Visual Basic]
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Struct _
Or AttributeTargets.Enum Or AttributeTargets.Interface)>
Public Class XmlTypeAttribute
Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Enum | AttributeTargets.Interface)]
public class XmlTypeAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class | AttributeTargets::Struct
| AttributeTargets::Enum | AttributeTargets::Interface)]
public __gc class XmlTypeAttribute : public Attribute
[JScript]
public
AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Enum | AttributeTargets.Interface)
class XmlTypeAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The XmlTypeAttribute belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.
You can apply the XmlTypeAttribute to a class, structure, enumeration, or interface declaration.
Apply the XmlTypeAttribute to a class to specify the XML type's namespace, the XML type name, and whether to include the type in the XML schema document. To see the results of setting the XmlTypeAttribute class's properties, compile your application as an executable or DLL, and pass the resulting file to the XML Schema Definition Tool (Xsd.exe). The tool writes the schema--including the type definition.
Note If you set the IncludeInSchema property to false, the XML Schema Definition Tool (Xsd.exe) will not include type in the schema. By default, for each public class, the XSD tool generates a complexType and an element of that type.
For more information about using attributes, see Extending Metadata Using Attributes.
Note In your code, you can use the word XmlType instead of the longer XmlTypeAttribute.
Example
[Visual Basic, C#, C++] The following example shows two classes to which the XmlTypeAttribute has been applied.
[Visual Basic]
<XmlType(Namespace := "http://www.cpandl.com", _
TypeName := "GroupMember")> _
Public Class Person
Public Name As String
End Class
<XmlType(Namespace := "http://www.cohowinery.com", _
TypeName := "GroupAddress")> _
Public Class Address
Public Line1 As String
Public Line2 As String
Public City As String
Public State As String
Public Zip As String
End Class
Public Class Group
Public Staff() As Person
Public Manager As Person
Public Location As Address
End Class
[C#]
[XmlType(Namespace = "http://www.cpandl.com",
TypeName = "GroupMember")]
public class Person
{
public string Name;
}
[XmlType(Namespace = "http://www.cohowinery.com",
TypeName = "GroupAddress")]
public class Address
{
public string Line1;
public string Line2;
public string City;
public string State;
public string Zip;
}
public class Group
{
public Person[] Staff;
public Person Manager;
public Address Location;
}
[C++]
[XmlType(Namespace = S"http://www.cpandl.com",
TypeName = S"GroupMember")]
public __gc class Person
{
public:
String* Name;
};
[XmlType(Namespace = S"http://www.cohowinery.com",
TypeName = S"GroupAddress")]
public __gc class Address
{
public:
String* Line1;
String* Line2;
String* City;
String* State;
String* Zip;
};
public __gc class Group
{
public:
Person* Staff[];
Person* Manager;
Address* Location;
};
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Xml.Serialization
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Xml (in System.Xml.dll)
See Also
XmlTypeAttribute Members | System.Xml.Serialization Namespace | Introducing XML Serialization | Overriding XML Serialization | XmlAttributes | Controlling XML Serialization Using Attributes | Examples of XML Serialization