Partager via


Name Attribute Binding Support

The .NET Framework provides binding support for the name attribute.

The value of the name attribute corresponds to the name of a public class or field, depending on the element to which the attribute is applied. An appropriate ***Name property can be applied to override the name produced when Xsd.exe generates an XSD document.

Generating source from XSD documents

The name attribute is used as follows for the elements for which Xsd.exe provides type bindings when generating source code from an XML Schema document:

<attribute>: Provides the name of the public class field that represents that attribute. The field appears with a System.Xml.Serialization.XmlAttributeAttribute.

<complexType>: Provides the name of the class that corresponds to the complex type.

<element>: Provides the name of the public class field that represents that element. If the <element> element contains an anonymous <complexType> definition, the name becomes the name of the class that corresponds to the complex type.

<simpleType>: Provides the name of the class that corresponds to the simple type. The .NET Framework allows the deriving of simple types only through (a) the enumeration of string-based types and (b) the creation of lists used as attributes.

No attempt is made to change case to adhere to coding conventions. For example, if the name attribute of a <complexType> element has the value testInfo, the ensuing class gets named testInfo, rather than the capitalized TestInfo. If a name conflicts with a reserved keyword, the resulting name is prepended with the symbol @.

The .NET Framework does not have bindings to the following XML Schema definition language elements used for establishing uniqueness and referential integrity: <key>, <keyref>, and <unique>. Accordingly, the name attribute's appearance in these elements is ignored. Likewise, there are no type bindings for the <notation> element, so the name attribute is ignored therein.

Since Xsd.exe does not directly support the <group> and <attributeGroup> elements—insteading expanding the contents of each reference into the class corresponding to each complex type that contains a reference—the group or attribute group name is ignored.

Generating XSD documents from classes

When Xsd.exe generates an XSD document from a set of classes in an assembly, it uses the previously described code constructs to provide values for the corresponding name attributes.

In addition, since public properties, in addition to fields, are translated into <element> and <attribute> elements, the property names by default are made the name attribute values.

An alternate name—name attribute value—can be supplied via the following attribute properties:

Possible containing elements: <attribute>, <attributeGroup>, <complexType>, <element>, <group>, <key>, <keyref>, <notation>, <simpleType>, <unique>

See Also

Reference

XmlSchemaAttribute.Name
XmlSchemaAttributeGroup.Name
XmlSchemaElement.Name
XmlSchemaGroup.Name
XmlSchemaType.Name
XmlSchemaComplexType
XmlSchemaSimpleType
XmlSchemaIdentityConstraint.Name
XmlSchemaKey
XmlSchemaKeyref
XmlSchemaUnique
XmlSchemaNotation.Name