svn path=/branches/mono-1-1-9/mcs/; revision=51216
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaAttribute.cs
1 //\r
2 // System.Xml.Schema.XmlSchemaAttribute.cs\r
3 //\r
4 // Authors:\r
5 //      Dwivedi, Ajay kumar  Adwiv@Yahoo.com\r
6 //      Enomoto, Atsushi     ginga@kit.hi-ho.ne.jp\r
7 //\r
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 using System;\r
30 using System.Xml;\r
31 using System.ComponentModel;\r
32 using System.Xml.Serialization;\r
33 \r
34 namespace System.Xml.Schema\r
35 {\r
36         /// <summary>\r
37         /// Summary description for XmlSchemaAttribute.\r
38         /// </summary>\r
39         public class XmlSchemaAttribute : XmlSchemaAnnotated\r
40         {\r
41                 private object attributeType;\r
42 #if NET_2_0\r
43                 private XmlSchemaSimpleType attributeSchemaType;\r
44 #endif\r
45                 private string defaultValue;\r
46                 private string fixedValue;\r
47                 private string validatedDefaultValue;\r
48                 private string validatedFixedValue;\r
49                 private XmlSchemaForm form;\r
50                 private string name;\r
51                 private string targetNamespace;\r
52                 private XmlQualifiedName qualifiedName;\r
53                 private XmlQualifiedName refName;\r
54                 private XmlSchemaSimpleType schemaType;\r
55                 private XmlQualifiedName schemaTypeName;\r
56                 private XmlSchemaUse use;\r
57                 private XmlSchemaUse validatedUse;\r
58                 //Compilation fields\r
59                 internal bool ParentIsSchema = false;\r
60                 private XmlSchemaAttribute referencedAttribute;\r
61                 const string xmlname = "attribute";\r
62 \r
63                 public XmlSchemaAttribute()\r
64                 {\r
65                         //LAMESPEC: Docs says the default is optional.\r
66                         //Whereas the MS implementation has default None.\r
67                         form    = XmlSchemaForm.None;\r
68                         use             = XmlSchemaUse.None;\r
69                         schemaTypeName  = XmlQualifiedName.Empty;\r
70                         qualifiedName   = XmlQualifiedName.Empty;\r
71                         refName                 = XmlQualifiedName.Empty;\r
72                 }\r
73 \r
74                 // Properties\r
75                 #region Properties\r
76 \r
77                 [DefaultValue(null)]\r
78                 [System.Xml.Serialization.XmlAttribute("default")]\r
79                 public string DefaultValue \r
80                 {\r
81                         get{ return defaultValue;}\r
82                         set\r
83                         { // Default Value and fixed Value are mutually exclusive\r
84                                 fixedValue = null;\r
85                                 defaultValue = value;\r
86                         }\r
87                 }\r
88 \r
89                 [DefaultValue(null)]\r
90                 [System.Xml.Serialization.XmlAttribute("fixed")]\r
91                 public string FixedValue \r
92                 {\r
93                         get{ return fixedValue;}\r
94                         set\r
95                         { // Default Value and fixed Value are mutually exclusive\r
96                                 defaultValue = null;\r
97                                 fixedValue = value;\r
98                         }\r
99                 }\r
100 \r
101                 [DefaultValue(XmlSchemaForm.None)]\r
102                 [System.Xml.Serialization.XmlAttribute("form")]\r
103                 public XmlSchemaForm Form \r
104                 {\r
105                         get{ return form;}\r
106                         set{ form = value;}\r
107                 }\r
108 \r
109                 [System.Xml.Serialization.XmlAttribute("name")]\r
110                 public string Name \r
111                 {\r
112                         get{ return name;}\r
113                         set\r
114                         {\r
115                                 name  = value;\r
116                         }\r
117                 }\r
118 \r
119                 [System.Xml.Serialization.XmlAttribute("ref")]\r
120                 public XmlQualifiedName RefName \r
121                 {\r
122                         get{ return refName;}\r
123                         set\r
124                         {\r
125                                 refName = value; \r
126                         }\r
127                 }\r
128                 \r
129                 [System.Xml.Serialization.XmlAttribute("type")]\r
130                 public XmlQualifiedName SchemaTypeName \r
131                 {\r
132                         get{ return schemaTypeName;}\r
133                         set{ schemaTypeName = value;}\r
134                 }\r
135 \r
136                 [XmlElement("simpleType")]\r
137                 public XmlSchemaSimpleType SchemaType \r
138                 {\r
139                         get{ return schemaType;}\r
140                         set{ schemaType = value;}\r
141                 }\r
142 \r
143                 [DefaultValue(XmlSchemaUse.None)]\r
144                 [System.Xml.Serialization.XmlAttribute("use")]\r
145                 public XmlSchemaUse Use \r
146                 {\r
147                         get{ return use;}\r
148                         set{ use = value;}\r
149                 }\r
150 \r
151                 [XmlIgnore]\r
152                 public XmlQualifiedName QualifiedName \r
153                 {\r
154                         get{ return qualifiedName;}\r
155                 }\r
156 \r
157                 [XmlIgnore]\r
158 #if NET_2_0\r
159                 [Obsolete]\r
160 #endif\r
161                 public object AttributeType \r
162                 {\r
163                         get{\r
164                                 if (referencedAttribute != null)\r
165                                         return referencedAttribute.AttributeType;\r
166                                 else\r
167                                         return attributeType;\r
168                         }\r
169                 }\r
170 \r
171 #if NET_2_0\r
172                 [XmlIgnore]\r
173                 public XmlSchemaSimpleType AttributeSchemaType\r
174                 {\r
175                         get {\r
176                                 if (referencedAttribute != null)\r
177                                         return referencedAttribute.AttributeSchemaType;\r
178                                 else\r
179                                         return attributeSchemaType;\r
180                         }\r
181                 }\r
182 #endif\r
183 \r
184                 // Post compilation default value (normalized)\r
185                 internal string ValidatedDefaultValue\r
186                 {\r
187                         // DefaultValue can be overriden in case of ref.\r
188                         get { return validatedDefaultValue; }\r
189                 }\r
190 \r
191                 // Post compilation fixed value (normalized)\r
192                 internal string ValidatedFixedValue \r
193                 {\r
194                         // FixedValue can be overriden in case of ref.\r
195                         get { return validatedFixedValue; }\r
196                 }\r
197                 internal XmlSchemaUse ValidatedUse\r
198                 {\r
199                         get { return validatedUse; }\r
200                 }\r
201 \r
202                 #endregion\r
203 \r
204                 /// <remarks>\r
205                 /// For an attribute:\r
206                 ///  a) If the parent is schema \r
207                 ///             1-5             are from <xs:complexType name="topLevelAttribute"> in the Schema for Schema\r
208                 ///             6-8             are from  "Constraints on XML Representations of Attribute Declarations"\r
209                 ///             9-10    are from "Attribute Declaration Schema Component"\r
210                 ///             11-16   are from "Constraints on Attribute Declaration Schema Components"\r
211                 ///             1. ref  must be absent\r
212                 ///             2. form must be absent\r
213                 ///             3. use  must be absent\r
214                 ///             4. name must be present and of type NCName\r
215                 ///             5. *NO CHECK REQUIRED* Only simple types and annotation are allowed as content\r
216                 ///             6. default and fixed must not both be present. \r
217                 ///             7. *NO CHECK REQUIRED* If default and use are both present... (Not possible since use is absent)\r
218                 ///             8. type and <simpleType> must not both be present.\r
219                 ///             9. Target Namespace should be schema's targetnamespace or absent\r
220                 ///             10. Type Definiton coressponds to <simpletype> element, or type value, or absent\r
221                 ///             11. *TO UNDERSTAND* Missing Sub-components\r
222                 ///             12. value constraint must be of the same datatype as of type\r
223                 ///             13. if the type definition is ID then there should be no value constraint.\r
224                 ///             14. name must not be xmlns\r
225                 ///             15. Targetnamespace must not be xsi. This implies the target namespace of schema can't be xsi if toplevel attributes are used.\r
226                 ///             16. *Exception to rule 15* inbuilt attributes: xsi:nil, xsi:type, xsi:schemaLocation, xsi: noNamespaceSchemaLocation\r
227                 ///     b) If the parent is complextype and ref is not set\r
228                 ///             1. name must be present and of type NCName.\r
229                 ///             2. type and <simpleType> must not both be present.\r
230                 ///             3. default and fixed must not both be present. \r
231                 ///     4. If default and use are both present, use must have the Â·actual value· optional.\r
232                 ///             5. name must not be xmlns\r
233                 ///             6. Targetnamespace must not be xsi.\r
234                 ///             7. *Exception to rule 15* inbuilt attributes: xsi:nil, xsi:type, xsi:schemaLocation, xsi: noNamespaceSchemaLocation\r
235                 ///             8. If form has actual value qualified or the schema's formdefault is qualified, targetnamespace\r
236                 ///                is same as schema's target namespace, otherwise absent.\r
237                 ///     c) if the parent is not schema and ref is set\r
238                 ///             1. name must not be present\r
239                 ///             2. all of <simpleType>, form and type must be absent. \r
240                 ///             3. default and fixed must not both be present. \r
241                 ///     4. If default and use are both present, use must have the Â·actual value· optional.\r
242                 /// </remarks>\r
243                 internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
244                 {\r
245                         // If this is already compiled this time, simply skip.\r
246                         if (this.IsComplied (schema.CompilationId))\r
247                                 return 0;\r
248 \r
249 #if NET_2_0\r
250                         if (schemaType != null)\r
251                                 schemaType.Parent = this;\r
252 #endif\r
253 \r
254                         errorCount = 0;\r
255                         \r
256                         if(ParentIsSchema || isRedefineChild)//a\r
257                         {\r
258                                 if(RefName!= null && !RefName.IsEmpty) // a.1\r
259                                         error(h,"ref must be absent in the top level <attribute>");\r
260                                 \r
261                                 if(Form != XmlSchemaForm.None)  // a.2\r
262                                         error(h,"form must be absent in the top level <attribute>");\r
263                                 \r
264                                 if(Use != XmlSchemaUse.None)            // a.3\r
265                                         error(h,"use must be absent in the top level <attribute>");\r
266 \r
267                                 targetNamespace = schema.TargetNamespace;\r
268 \r
269                                 CompileCommon (h, schema, true);\r
270                         }\r
271                         else // local\r
272                         {\r
273                                 // Q:How to Use of AttributeFormDefault????\r
274                                 // A:Global attribute cannot be defined locally\r
275                                 if(RefName == null || RefName.IsEmpty)\r
276                                 {\r
277                                         if(form == XmlSchemaForm.Qualified || (form == XmlSchemaForm.None && schema.AttributeFormDefault == XmlSchemaForm.Qualified))\r
278                                                 this.targetNamespace = schema.TargetNamespace;\r
279                                         else\r
280                                                 this.targetNamespace = "";\r
281 \r
282                                         CompileCommon(h, schema, true);\r
283                                 }\r
284                                 else\r
285                                 {\r
286                                         if(this.name != null)\r
287                                                 error(h,"name must be absent if ref is present");\r
288                                         if(this.form != XmlSchemaForm.None)\r
289                                                 error(h,"form must be absent if ref is present");\r
290                                         if(this.schemaType != null)\r
291                                                 error(h,"simpletype must be absent if ref is present");\r
292                                         if(this.schemaTypeName != null && !this.schemaTypeName.IsEmpty)\r
293                                                 error(h,"type must be absent if ref is present");\r
294 \r
295                                         CompileCommon(h, schema, false);\r
296                                 }\r
297                         }\r
298 \r
299                         this.CompilationId = schema.CompilationId;\r
300                         return errorCount;\r
301                 }\r
302                 \r
303                 private void CompileCommon(ValidationEventHandler h, XmlSchema schema, bool refIsNotPresent)\r
304                 {\r
305                         if(refIsNotPresent)\r
306                         {\r
307                                 if(Name == null)        //a.4, b.1, \r
308                                         error(h,"Required attribute name must be present");\r
309                                 else if(!XmlSchemaUtil.CheckNCName(Name)) // a.4.2, b1.2\r
310                                         error(h,"attribute name must be NCName");\r
311                                 else if(Name == "xmlns") // a.14 , b5\r
312                                         error(h,"attribute name must not be xmlns");\r
313                                 else\r
314                                         qualifiedName = new XmlQualifiedName(Name, targetNamespace);\r
315 \r
316                                 if(SchemaType != null)\r
317                                 {\r
318                                         if(SchemaTypeName != null && !SchemaTypeName.IsEmpty) // a.8\r
319                                                 error(h,"attribute can't have both a type and <simpleType> content");\r
320 \r
321                                         errorCount += SchemaType.Compile(h, schema); \r
322                                 }\r
323 \r
324                                 if(SchemaTypeName != null && !XmlSchemaUtil.CheckQName(SchemaTypeName))\r
325                                         error(h,SchemaTypeName+" is not a valid QName");\r
326                         }\r
327                         else\r
328                         {\r
329                                 if(RefName == null || RefName.IsEmpty) \r
330                                         throw new InvalidOperationException ("Error: Should Never Happen. refname must be present");\r
331                                 else\r
332                                         qualifiedName = RefName;\r
333                         }\r
334 \r
335                         if(schema.TargetNamespace == XmlSchema.InstanceNamespace && Name != "nil" && Name != "type" \r
336                                 && Name != "schemaLocation" && Name != "noNamespaceSchemaLocation") // a.15, a.16\r
337                                 error(h,"targetNamespace can't be " + XmlSchema.InstanceNamespace);\r
338 \r
339                         if(DefaultValue != null && FixedValue != null) // a.6, b.3, c.3\r
340                                 error(h,"default and fixed must not both be present in an Attribute");\r
341 \r
342                         if(DefaultValue != null && Use != XmlSchemaUse.None && Use != XmlSchemaUse.Optional)\r
343                                 error(h,"if default is present, use must be optional");\r
344 \r
345                         XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);\r
346                 }\r
347 \r
348                 /// <summary>\r
349                 /// Schema Component: \r
350                 ///                     QName, SimpleType, Scope, Default|Fixed, annotation\r
351                 /// </summary>\r
352                 internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
353                 {\r
354                         if(IsValidated (schema.ValidationId))\r
355                                 return errorCount;\r
356 \r
357                         // -- Attribute Declaration Schema Component --\r
358                         // {name}, {target namespace} -> QualifiedName. Already Compile()d.\r
359                         // {type definition} -> attributeType. From SchemaType or SchemaTypeName.\r
360                         // {scope} -> ParentIsSchema | isRedefineChild.\r
361                         // {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue.\r
362                         // {annotation}\r
363                         // -- Attribute Use Schema Component --\r
364                         // {required}\r
365                         // {attribute declaration}\r
366                         // {value constraint}\r
367 \r
368                         // First, fill type information for type reference\r
369                         if (SchemaType != null) {\r
370                                 SchemaType.Validate (h, schema);\r
371                                 attributeType = SchemaType;\r
372                         }\r
373                         else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty)\r
374                         {\r
375                                 // If type is null, then it is missing sub components .\r
376                                 XmlSchemaType type = schema.SchemaTypes [SchemaTypeName] as XmlSchemaType;\r
377                                 if (type is XmlSchemaComplexType)\r
378                                         error(h,"An attribute can't have complexType Content");\r
379                                 else if (type != null) {        // simple type\r
380                                         errorCount += type.Validate (h, schema);\r
381                                         attributeType = type;\r
382                                 }\r
383                                 else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName)\r
384                                         attributeType = XmlSchemaComplexType.AnyType;
385                                 else if (XmlSchemaUtil.IsBuiltInDatatypeName (SchemaTypeName)) {\r
386                                         attributeType = XmlSchemaDatatype.FromName (SchemaTypeName);\r
387                                         if (attributeType == null)\r
388                                                 error (h, "Invalid xml schema namespace datatype was specified.");\r
389                                 }\r
390                                 // otherwise, it might be missing sub components.\r
391                                 else if (!schema.IsNamespaceAbsent (SchemaTypeName.Namespace))\r
392                                         error (h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema.");\r
393                         }\r
394 \r
395                         // Then, fill type information for the type references for the referencing attributes\r
396                         if (RefName != null && RefName != XmlQualifiedName.Empty)\r
397                         {\r
398                                 referencedAttribute = schema.Attributes [RefName] as XmlSchemaAttribute;\r
399                                 // If el is null, then it is missing sub components .\r
400                                 if (referencedAttribute != null)\r
401                                         errorCount += referencedAttribute.Validate (h, schema);\r
402                                 // otherwise, it might be missing sub components.\r
403                                 else if (!schema.IsNamespaceAbsent (RefName.Namespace))\r
404                                         error (h, "Referenced attribute " + RefName + " was not found in the corresponding schema.");\r
405                         }\r
406 \r
407                         if (attributeType == null)\r
408                                 attributeType = XmlSchemaSimpleType.AnySimpleType;\r
409 \r
410                         // Validate {value constraints}\r
411                         if (defaultValue != null || fixedValue != null) {\r
412                                 XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype;\r
413                                 if (datatype == null)\r
414                                         datatype = ((XmlSchemaSimpleType) attributeType).Datatype;\r
415                                 if (datatype.TokenizedType == XmlTokenizedType.QName)\r
416                                         error (h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values.");\r
417                                 else {\r
418                                         try {\r
419                                                 if (defaultValue != null) {\r
420                                                         validatedDefaultValue = datatype.Normalize (defaultValue);\r
421                                                         datatype.ParseValue (validatedDefaultValue, null, null);\r
422                                                 }\r
423                                         } catch (Exception ex) {\r
424                                                 // FIXME: This is not a good way to handle exception.\r
425                                                 error (h, "The Attribute's default value is invalid with its type definition.", ex);\r
426                                         }\r
427                                         try {\r
428                                                 if (fixedValue != null) {\r
429                                                         validatedFixedValue = datatype.Normalize (fixedValue);\r
430                                                         datatype.ParseValue (validatedFixedValue, null, null);\r
431                                                 }\r
432                                         } catch (Exception ex) {\r
433                                                 // FIXME: This is not a good way to handle exception.\r
434                                                 error (h, "The Attribute's fixed value is invalid with its type definition.", ex);\r
435                                         }\r
436                                 }\r
437                         }\r
438                         if (Use == XmlSchemaUse.None)\r
439                                 validatedUse = XmlSchemaUse.Optional;\r
440                         else\r
441                                 validatedUse = Use;\r
442 \r
443 #if NET_2_0\r
444                         attributeSchemaType = attributeType as XmlSchemaSimpleType;\r
445                         if (attributeSchemaType == null)\r
446                                 attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType (((XmlSchemaDatatype) attributeType).TypeCode);\r
447 #endif\r
448 \r
449                         ValidationId = schema.ValidationId;\r
450                         return errorCount;\r
451                 }\r
452 \r
453                 //<attribute\r
454                 //  default = string\r
455                 //  fixed = string\r
456                 //  form = (qualified | unqualified)\r
457                 //  id = ID\r
458                 //  name = NCName\r
459                 //  ref = QName\r
460                 //  type = QName\r
461                 //  use = (optional | prohibited | required) : optional\r
462                 //  {any attributes with non-schema namespace . . .}>\r
463                 //  Content: (annotation?, (simpleType?))\r
464                 //</attribute>\r
465                 internal static XmlSchemaAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)\r
466                 {\r
467                         XmlSchemaAttribute attribute = new XmlSchemaAttribute();\r
468                         reader.MoveToElement();\r
469 \r
470                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
471                         {\r
472                                 error(h,"Should not happen :1: XmlSchemaAttribute.Read, name="+reader.Name,null);\r
473                                 reader.SkipToEnd();\r
474                                 return null;\r
475                         }\r
476 \r
477                         attribute.LineNumber = reader.LineNumber;\r
478                         attribute.LinePosition = reader.LinePosition;\r
479                         attribute.SourceUri = reader.BaseURI;\r
480 \r
481                         while(reader.MoveToNextAttribute())\r
482                         {\r
483                                 if(reader.Name == "default")\r
484                                 {\r
485                                         attribute.defaultValue = reader.Value;\r
486                                 }\r
487                                 else if(reader.Name == "fixed")\r
488                                 {\r
489                                         attribute.fixedValue = reader.Value;\r
490                                 }\r
491                                 else if(reader.Name == "form")\r
492                                 {\r
493                                         Exception innerex;\r
494                                         attribute.form = XmlSchemaUtil.ReadFormAttribute(reader,out innerex);\r
495                                         if(innerex != null)\r
496                                                 error(h, reader.Value + " is not a valid value for form attribute", innerex);\r
497                                 }\r
498                                 else if(reader.Name == "id")\r
499                                 {\r
500                                         attribute.Id = reader.Value;\r
501                                 }\r
502                                 else if(reader.Name == "name")\r
503                                 {\r
504                                         attribute.name = reader.Value;\r
505                                 }\r
506                                 else if(reader.Name == "ref")\r
507                                 {\r
508                                         Exception innerex;\r
509                                         attribute.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);\r
510                                         if(innerex != null)\r
511                                                 error(h, reader.Value + " is not a valid value for ref attribute",innerex);\r
512                                 }\r
513                                 else if(reader.Name == "type")\r
514                                 {\r
515                                         Exception innerex;\r
516                                         attribute.schemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);\r
517                                         if(innerex != null)\r
518                                                 error(h, reader.Value + " is not a valid value for type attribute",innerex);\r
519                                 }\r
520                                 else if(reader.Name == "use")\r
521                                 {\r
522                                         Exception innerex;\r
523                                         attribute.use = XmlSchemaUtil.ReadUseAttribute(reader,out innerex);\r
524                                         if(innerex != null)\r
525                                                 error(h, reader.Value + " is not a valid value for use attribute", innerex);\r
526                                 }\r
527                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
528                                 {\r
529                                         error(h,reader.Name + " is not a valid attribute for attribute",null);\r
530                                 }\r
531                                 else\r
532                                 {\r
533                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,attribute);\r
534                                 }\r
535                         }\r
536                         \r
537                         reader.MoveToElement();\r
538                         if(reader.IsEmptyElement)\r
539                                 return attribute;\r
540 \r
541                         //  Content: (annotation?, (simpleType?))\r
542                         int level = 1;\r
543                         while(reader.ReadNextElement())\r
544                         {\r
545                                 if(reader.NodeType == XmlNodeType.EndElement)\r
546                                 {\r
547                                         if(reader.LocalName != xmlname)\r
548                                                 error(h,"Should not happen :2: XmlSchemaAttribute.Read, name="+reader.Name,null);\r
549                                         break;\r
550                                 }\r
551                                 if(level <= 1 && reader.LocalName == "annotation")\r
552                                 {\r
553                                         level = 2; //Only one annotation\r
554                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
555                                         if(annotation != null)\r
556                                                 attribute.Annotation = annotation;\r
557                                         continue;\r
558                                 }\r
559                                 if(level <=2 && reader.LocalName == "simpleType")\r
560                                 {\r
561                                         level = 3;\r
562                                         XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);\r
563                                         if(stype != null)\r
564                                                 attribute.schemaType = stype;\r
565                                         continue;\r
566                                 }\r
567                                 reader.RaiseInvalidElementError();\r
568                         }\r
569                         return attribute;\r
570                 }\r
571                 \r
572         }\r
573 }\r