public class XmlSchemaAttribute : XmlSchemaAnnotated
|
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>
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
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. |
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. |
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:
public XmlSchemaAttribute(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public object AttributeType {get;}
|
public string DefaultValue {get; set;}
|
Optional.
The default is null.
public string FixedValue {get; set;}
|
Optional.
public XmlSchemaForm Form {get; set;}
|
public string Id {get; set;}
|
Optional.
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public string Name {get; set;}
|
Optional.
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlQualifiedName QualifiedName {get;}
|
public XmlQualifiedName RefName {get; set;}
|
Optional.
public XmlSchemaSimpleType SchemaType {get; set;}
|
public XmlQualifiedName SchemaTypeName {get; set;}
|
Optional.
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
public XmlSchemaUse Use {get; set;}
|
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. |
~XmlSchemaAttribute(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |