XmlTypeAttribute Class
Assembly: System.Xml (in system.xml.dll)
'Declaration <AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Interface)> _ Public Class XmlTypeAttribute Inherits Attribute 'Usage Dim instance As XmlTypeAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Interface) */ public class XmlTypeAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Interface) public class XmlTypeAttribute extends Attribute
Not applicable.
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.
Note: |
|---|
| If you set the IncludeInSchema property to false, the XML Schema Definition Tool (Xsd.exe) does not include the 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: |
|---|
| 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
/** @attribute XmlType(Namespace = "http://www.cpandl.com",
TypeName = "GroupMember")
*/
public class Person
{
public String name;
} //Person
/** @attribute 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;
} //Address
public class Group
{
public Person staff[];
public Person manager;
public Address location;
} //Group
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
XmlTypeAttribute MembersSystem.Xml.Serialization Namespace
XmlAttributeOverrides
XmlAttributes
XmlSerializer
XmlAttributes.XmlText Property
Other Resources
Introducing XML SerializationHow to: Specify an Alternate Element Name for an XML Stream
Controlling XML Serialization Using Attributes
Examples of XML Serialization
Note: