System.Xml.Serialization.XmlRootAttribute Class

Controls XML serialization of the attribute target as an XML root element.

See Also: XmlRootAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.ReturnValue | System.AttributeTargets.All)]
public class XmlRootAttribute : Attribute

Remarks

The System.Xml.Serialization.XmlRootAttribute belongs to a family of attributes that controls how the System.Xml.Serialization.XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.

You can apply the System.Xml.Serialization.XmlRootAttribute to a class, structure, enumeration, or interface. You can also apply the attribute to the return value of an XML Web service method.

Every XML document must have a single root element that contains all the other elements. The System.Xml.Serialization.XmlRootAttribute allows you to control how the System.Xml.Serialization.XmlSerializer generates the root element by setting certain properties. For example, specify the name of the generated XML element by setting the XmlRootAttribute.ElementName property.

For more information about using attributes, see Extending Metadata Using Attributes.

Note:

You can use the word XmlRoot in your code instead of the longer System.Xml.Serialization.XmlRootAttribute.

Requirements

Namespace: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0