Controls the XML schema that is generated when the attribute target is serialized by the XmlSerializer.
Namespace:
System.Xml.Serialization
Assembly:
System.Xml (in System.Xml.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Interface)> _
Public Class XmlTypeAttribute _
Inherits Attribute
Dim instance As XmlTypeAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Interface)]
public class XmlTypeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Interface)]
public ref class XmlTypeAttribute : public Attribute
public class XmlTypeAttribute extends Attribute
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 properties of the XmlTypeAttribute class, 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.
For more information about using attributes, see Extending Metadata Using Attributes.
Note: |
|---|
You can use the word XmlType in your code instead of the longer XmlTypeAttribute. |
The following example shows two classes to which the XmlTypeAttribute has been applied.
<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
[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;
}
[XmlType(Namespace="http://www.cpandl.com",
TypeName="GroupMember")]
public ref class Person
{
public:
String^ Name;
};
[XmlType(Namespace="http://www.cohowinery.com",
TypeName="GroupAddress")]
public ref class Address
{
public:
String^ Line1;
String^ Line2;
String^ City;
String^ State;
String^ Zip;
};
public ref class Group
{
public:
array<Person^>^Staff;
Person^ Manager;
Address^ Location;
};
[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;
};
System..::.Object
System..::.Attribute
System.Xml.Serialization..::.XmlTypeAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference
Other Resources