System.Xml.Schema.XmlSchemaAttribute Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Class for attribute types. Represents the World Wide Web Consortium (W3C) attribute element.
C# Syntax:
public class XmlSchemaAttribute : XmlSchemaAnnotated
Remarks
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.
Example
The following example creates the attribute element.
using System;
using System.Xml;  
using System.Xml.Schema;

class XMLSchemaExamples {
    public static void Main() {
 
        XmlSchema schema = new XmlSchema();

        // <xs:attribute name="mybaseattribute">
        XmlSchemaAttribute attributeBase = new XmlSchemaAttribute();
        schema.Items.Add(attributeBase);
        attributeBase.Name = "mybaseattribute";
        
        // <xs:simpleType>
        XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
        attributeBase.SchemaType = simpleType;
        
        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
        simpleType.Content = restriction;
        restriction.BaseTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
        restriction.Facets.Add(maxInclusive);
        maxInclusive.Value = "1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        schema.Items.Add(complexType);
        complexType.Name = "myComplexType";
        
        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute attributeBaseRef = new XmlSchemaAttribute();
        complexType.Attributes.Add(attributeBaseRef);
        attributeBaseRef.RefName = new XmlQualifiedName("mybaseattribute");
        
        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
 	XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

        Console.WriteLine(args.Message);
    }
}

    

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>

    
See also:
System.Xml.Schema Namespace

System.Xml.Schema.XmlSchemaAttribute Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Properties
Annotation
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation


Gets or sets the annotation property.
AttributeType Read-only

Gets the common runtime library (CLR) object based on the XmlSchemaAttribute.SchemaType or XmlSchemaAttribute.SchemaTypeName of the attribute that holds the post-compilation value of the AttributeType property.
DefaultValue Read-write

Gets or sets the default value for the attribute.
FixedValue Read-write

Gets or sets the fixed value for the attribute.
Form Read-write

Gets or sets the form for the attribute.
Id
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id


Gets or sets the string id.
LineNumber
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber


Gets or sets the line number in the file to which the schema element refers.
LinePosition
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition


Gets or sets the line position in the file to which the schema element refers.
Name Read-write

Gets or sets the name of the attribute.
Namespaces
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces


QualifiedName Read-only

Gets the qualified name for the attribute which holds the post-compilation value of the QualifiedName property.
RefName Read-write

Gets or sets the name of an attribute declared in this schema (or another schema indicated by the specified namespace).
SchemaType Read-write

Gets or sets the attribute type to a simple type.
SchemaTypeName Read-write

Gets or sets the name of the simple type defined in this schema (or another schema indicated by the specified namespace).
SourceUri
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri


Gets or sets the source location for the file that loaded the schema.
UnhandledAttributes
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes


Gets or sets the qualified attributes that do not belong to the schema target namespace.
Use Read-write

Gets or sets information about how the attribute is used.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Schema.XmlSchemaAttribute Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public XmlSchemaAttribute();

Return to top


Property: Annotation (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation

Summary
Gets or sets the annotation property.
C# Syntax:
public XmlSchemaAnnotation Annotation {get; set;}

Return to top


Property: AttributeType (read-only)
Summary
Gets the common runtime library (CLR) object based on the XmlSchemaAttribute.SchemaType or XmlSchemaAttribute.SchemaTypeName of the attribute that holds the post-compilation value of the AttributeType property.
C# Syntax:
public object AttributeType {get;}
Remarks
The object can be XmlSchemaDatatype if the attribute has a built-in XML Schema type or XmlSchemaSimpleType if the attribute has a user-defined type. This property is a post-schema-validation infoset property.

Return to top


Property: DefaultValue (read-write)
Summary
Gets or sets the default value for the attribute.
C# Syntax:
public string DefaultValue {get; set;}
Remarks
DefaultValue property indicates that the attribute is to appear unconditionally in the XML document, using the supplied value whenever the attribute is not present. By default, this property is set to null to indicate that no default value is supplied for the attribute. The fixed and default properties are mutually exclusive.

Optional.

The default is null.

Return to top


Property: FixedValue (read-write)
Summary
Gets or sets the fixed value for the attribute.
C# Syntax:
public string FixedValue {get; set;}
Remarks
FixedValue indicates that the attribute value, if present, must equal the supplied value. By default, this property is set to null which means that no fixed value is supplied for the attribute. The fixed and default properties are mutually exclusive.

Optional.

Return to top


Property: Form (read-write)
Summary
Gets or sets the form for the attribute.
C# Syntax:
public XmlSchemaForm Form {get; set;}

Return to top


Property: Id (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id

Summary
Gets or sets the string id.
C# Syntax:
public string Id {get; set;}
Remarks
The id value must be of type ID and be unique within the document containing this element.

Optional.

Return to top


Property: LineNumber (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber

Summary
Gets or sets the line number in the file to which the schema element refers.
C# Syntax:
public int LineNumber {get; set;}
Remarks
LineNumber is used to store the line number when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: LinePosition (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition

Summary
Gets or sets the line position in the file to which the schema element refers.
C# Syntax:
public int LinePosition {get; set;}
Remarks
This is used to store the line position when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: Name (read-write)
Summary
Gets or sets the name of the attribute.
C# Syntax:
public string Name {get; set;}
Remarks
The name must be an NCName (no-colon name) as defined in the World Wide Web Consortium (W3C) XML Namespaces specification. When an XML document is validated against a schema, each attribute in the document is validated against an attribute element in the schema. The attribute element with a name attribute that matches the local name of the attribute in the document is used to validate that attribute. The Name and RefName properties are mutually exclusive.

Optional.

Return to top


Property: Namespaces (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces

C# Syntax:
public XmlSerializerNamespaces Namespaces {get; set;}

Return to top


Property: QualifiedName (read-only)
Summary
Gets the qualified name for the attribute which holds the post-compilation value of the QualifiedName property.
C# Syntax:
public XmlQualifiedName QualifiedName {get;}
Remarks
Optional.

Return to top


Property: RefName (read-write)
Summary
Gets or sets the name of an attribute declared in this schema (or another schema indicated by the specified namespace).
C# Syntax:
public XmlQualifiedName RefName {get; set;}
Remarks
The RefName must be a QName. The type can include a namespace prefix. The Name and RefName properties are mutually exclusive.

Optional.

Return to top


Property: SchemaType (read-write)
Summary
Gets or sets the attribute type to a simple type.
C# Syntax:
public XmlSchemaSimpleType SchemaType {get; set;}
Remarks
SchemaTypeName and SchemaType properties cannot be set at the same time.

Return to top


Property: SchemaTypeName (read-write)
Summary
Gets or sets the name of the simple type defined in this schema (or another schema indicated by the specified namespace).
C# Syntax:
public XmlQualifiedName SchemaTypeName {get; set;}
Remarks
SchemaTypeName and XmlSchemaAttribute.SchemaType properties cannot be set at the same time. The type must be a QName. The type can include a namespace prefix.

Optional.

Return to top


Property: SourceUri (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri

Summary
Gets or sets the source location for the file that loaded the schema.
C# Syntax:
public string SourceUri {get; set;}
Remarks
Provides information for exception handling.

Return to top


Property: UnhandledAttributes (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes

Summary
Gets or sets the qualified attributes that do not belong to the schema target namespace.
C# Syntax:
public XmlAttribute[] UnhandledAttributes {get; set;}

Return to top


Property: Use (read-write)
Summary
Gets or sets information about how the attribute is used.
C# Syntax:
public XmlSchemaUse Use {get; set;}
Remarks
If specified, this attribute must have one of the values shown in the following table.

Enum Description
None Attribute has no value.
Prohibited Attribute cannot be used.
Optional Attribute is optional and may have any value. This is the default.
Required Attribute must appear once.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlSchemaAttribute();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.