XmlSchemaAttribute Class
Represents the attribute element from the XML Schema as specified by the World Wide Web Consortium (W3C). Attributes provide additional information for other document elements. The attribute tag is nested between the tags of a document's element for the schema. The XML document displays attributes as named items in the opening tag of an element.
Assembly: System.Xml (in System.Xml.dll)
System.Xml.Schema::XmlSchemaObject
System.Xml.Schema::XmlSchemaAnnotated
System.Xml.Schema::XmlSchemaAttribute
| Name | Description | |
|---|---|---|
![]() | XmlSchemaAttribute() | Initializes a new instance of the XmlSchemaAttribute class. |
| Name | Description | |
|---|---|---|
![]() | Annotation | Gets or sets the annotation property.(Inherited from XmlSchemaAnnotated.) |
![]() | AttributeSchemaType | Gets an XmlSchemaSimpleType object representing the type of the attribute based on the SchemaType or SchemaTypeName of the attribute. |
![]() | AttributeType | Obsolete. Gets the common language runtime (CLR) object based on the SchemaType or SchemaTypeName of the attribute that holds the post-compilation value of the AttributeType property. |
![]() | DefaultValue | Gets or sets the default value for the attribute. |
![]() | FixedValue | Gets or sets the fixed value for the attribute. |
![]() | Form | Gets or sets the form for the attribute. |
![]() | Id | Gets or sets the string id.(Inherited from XmlSchemaAnnotated.) |
![]() | LineNumber | Gets or sets the line number in the file to which the schema element refers.(Inherited from XmlSchemaObject.) |
![]() | LinePosition | Gets or sets the line position in the file to which the schema element refers.(Inherited from XmlSchemaObject.) |
![]() | Name | Gets or sets the name of the attribute. |
![]() | Namespaces | Gets or sets the XmlSerializerNamespaces to use with this schema object.(Inherited from XmlSchemaObject.) |
![]() | Parent | Gets or sets the parent of this XmlSchemaObject.(Inherited from XmlSchemaObject.) |
![]() | QualifiedName | Gets the qualified name for the attribute. |
![]() | RefName | Gets or sets the name of an attribute declared in this schema (or another schema indicated by the specified namespace). |
![]() | SchemaType | Gets or sets the attribute type to a simple type. |
![]() | SchemaTypeName | Gets or sets the name of the simple type defined in this schema (or another schema indicated by the specified namespace). |
![]() | SourceUri | Gets or sets the source location for the file that loaded the schema.(Inherited from XmlSchemaObject.) |
![]() | UnhandledAttributes | Gets or sets the qualified attributes that do not belong to the current schema's target namespace.(Inherited from XmlSchemaAnnotated.) |
![]() | Use | Gets or sets information about how the attribute is used. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
Attribute declarations can be present as child elements of the schema element (having global scope) or within complex type definitions. For complex types, attribute declarations can be present as local declarations or references to attributes with global scope. Both global and local attribute declarations have the optional type attribute that refers to an existing simple type. If the optional type attribute is not used, the attribute declaration (global or local) must define a local simple type.
The following example creates the attribute element.
#using <mscorlib.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; class XmlSchemaExamples { public: static void Main() { XmlSchema^ schema = gcnew XmlSchema(); // <xs:attribute name="mybaseattribute"> XmlSchemaAttribute^ attributeBase = gcnew XmlSchemaAttribute(); schema->Items->Add(attributeBase); attributeBase->Name = "mybaseattribute"; // <xs:simpleType> XmlSchemaSimpleType^ simpleType = gcnew XmlSchemaSimpleType(); attributeBase->SchemaType = simpleType; // <xs:restriction base="integer"> XmlSchemaSimpleTypeRestriction^ restriction = gcnew XmlSchemaSimpleTypeRestriction(); simpleType->Content = restriction; restriction->BaseTypeName = gcnew XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema"); // <xs:maxInclusive value="1000"/> XmlSchemaMaxInclusiveFacet^ maxInclusive = gcnew XmlSchemaMaxInclusiveFacet(); restriction->Facets->Add(maxInclusive); maxInclusive->Value = "1000"; // <xs:complexType name="myComplexType"> XmlSchemaComplexType^ complexType = gcnew XmlSchemaComplexType(); schema->Items->Add(complexType); complexType->Name = "myComplexType"; // <xs:attribute ref="mybaseattribute"/> XmlSchemaAttribute^ attributeBaseRef = gcnew XmlSchemaAttribute(); complexType->Attributes->Add(attributeBaseRef); attributeBaseRef->RefName = gcnew XmlQualifiedName("mybaseattribute"); XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet(); schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne); schemaSet->Add(schema); schemaSet->Compile(); XmlSchema^ compiledSchema; for each (XmlSchema^ schema1 in schemaSet->Schemas()) { compiledSchema = schema1; } XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable()); nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema->Write(Console::Out, nsmgr); } static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args) { Console::WriteLine(args->Message); } }; int main() { XmlSchemaExamples::Main(); return 0; };
The following XML file is generated for the preceding code example.
<?xml version="1.0" encoding="IBM437"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:attribute name="mybaseattribute"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:maxInclusive value="1000" /> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:complexType name="myComplexType"> <xs:attribute ref="mybaseattribute" /> </xs:complexType> </xs:schema>
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


