You can apply the 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 XmlRootAttribute allows you to control how the XmlSerializer generates the root element by setting certain properties. For example, specify the name of the generated XML element by setting the ElementName property.

The following example applies the XmlRootAttribute to a class. The attribute specifies the element name, namespace, and whether the element is qualified, and whether the xsi:nil attribute is generated if the class is set to null.