1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSchemaAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Collections;
9 using System.ComponentModel;
10 using System.Xml.Serialization;
12 namespace System.Xml.Schema {
14 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute"]/*' />
16 /// <para>[To be supplied.]</para>
18 public class XmlSchemaAttribute : XmlSchemaAnnotated {
23 XmlSchemaForm form = XmlSchemaForm.None;
24 XmlSchemaUse use = XmlSchemaUse.None;
26 XmlQualifiedName refName = XmlQualifiedName.Empty;
27 XmlQualifiedName typeName = XmlQualifiedName.Empty;
28 XmlQualifiedName qualifiedName = XmlQualifiedName.Empty;
30 XmlSchemaSimpleType type;
31 XmlSchemaSimpleType attributeType;
35 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.DefaultValue"]/*' />
37 /// <para>[To be supplied.]</para>
39 [XmlAttribute("default")]
41 public string DefaultValue {
42 get { return defaultValue; }
43 set { defaultValue = value; }
46 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.FixedValue"]/*' />
48 /// <para>[To be supplied.]</para>
50 [XmlAttribute("fixed")]
52 public string FixedValue {
53 get { return fixedValue; }
54 set { fixedValue = value; }
57 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Form"]/*' />
59 /// <para>[To be supplied.]</para>
61 [XmlAttribute("form"), DefaultValue(XmlSchemaForm.None)]
62 public XmlSchemaForm Form {
67 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Name"]/*' />
69 /// <para>[To be supplied.]</para>
71 [XmlAttribute("name")]
77 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.RefName"]/*' />
79 /// <para>[To be supplied.]</para>
82 public XmlQualifiedName RefName {
83 get { return refName; }
84 set { refName = (value == null ? XmlQualifiedName.Empty : value); }
87 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaTypeName"]/*' />
89 /// <para>[To be supplied.]</para>
91 [XmlAttribute("type")]
92 public XmlQualifiedName SchemaTypeName {
93 get { return typeName; }
94 set { typeName = (value == null ? XmlQualifiedName.Empty : value); }
97 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaType"]/*' />
99 /// <para>[To be supplied.]</para>
101 [XmlElement("simpleType")]
102 public XmlSchemaSimpleType SchemaType {
104 set { type = value; }
107 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Use"]/*' />
109 /// <para>[To be supplied.]</para>
111 [XmlAttribute("use"), DefaultValue(XmlSchemaUse.None)]
112 public XmlSchemaUse Use {
117 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.QualifiedName"]/*' />
119 /// <para>[To be supplied.]</para>
122 public XmlQualifiedName QualifiedName {
123 get { return qualifiedName; }
126 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeType"]/*' />
128 /// <para>[To be supplied.]</para>
131 [Obsolete("This property has been deprecated. Please use AttributeSchemaType property that returns a strongly typed attribute type. http://go.microsoft.com/fwlink/?linkid=14202")]
132 public object AttributeType {
134 if (attributeType == null)
137 if (attributeType.QualifiedName.Namespace == XmlReservedNs.NsXs) {
138 return attributeType.Datatype;
140 return attributeType;
144 /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeSchemaType"]/*' />
146 /// <para>[To be supplied.]</para>
149 public XmlSchemaSimpleType AttributeSchemaType {
150 get { return attributeType; }
153 internal XmlReader Validate(XmlReader reader, XmlResolver resolver, XmlSchemaSet schemaSet, ValidationEventHandler valEventHandler) {
154 if (schemaSet != null) {
155 XmlReaderSettings readerSettings = new XmlReaderSettings();
156 readerSettings.ValidationType = ValidationType.Schema;
157 readerSettings.Schemas = schemaSet;
158 readerSettings.ValidationEventHandler += valEventHandler;
159 return new XsdValidatingReader(reader, resolver, readerSettings, this);
165 internal XmlSchemaDatatype Datatype {
167 if (attributeType != null) {
168 return attributeType.Datatype;
174 internal void SetQualifiedName(XmlQualifiedName value) {
175 qualifiedName = value;
178 internal void SetAttributeType(XmlSchemaSimpleType value) {
179 attributeType = value;
182 internal SchemaAttDef AttDef {
183 get { return attDef; }
184 set { attDef = value; }
187 internal bool HasDefault {
188 get { return defaultValue != null; }
192 internal override string NameAttribute {
194 set { Name = value; }
197 internal override XmlSchemaObject Clone() {
198 XmlSchemaAttribute newAtt = (XmlSchemaAttribute)MemberwiseClone();
200 //Deep clone the QNames as these will be updated on chameleon includes
201 newAtt.refName = this.refName.Clone();
202 newAtt.typeName = this.typeName.Clone();
203 newAtt.qualifiedName = this.qualifiedName.Clone();