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