XmlSchemaAttributeGroup.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. using System.Xml;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaAttributeGroup.
  10. /// </summary>
  11. public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
  12. {
  13. private XmlSchemaAnyAttribute any;
  14. private XmlSchemaObjectCollection attributes;
  15. private string name;
  16. private XmlSchemaAttributeGroup redefined;
  17. private XmlQualifiedName qualifiedName;
  18. private static string xmlname = "attributeGroup";
  19. public XmlSchemaAttributeGroup()
  20. {
  21. attributes = new XmlSchemaObjectCollection();
  22. }
  23. [System.Xml.Serialization.XmlAttribute("name")]
  24. public string Name
  25. {
  26. get{ return name;}
  27. set{ name = value;}
  28. }
  29. [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
  30. [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  31. public XmlSchemaObjectCollection Attributes
  32. {
  33. get{ return attributes;}
  34. }
  35. [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
  36. public XmlSchemaAnyAttribute AnyAttribute
  37. {
  38. get{ return any;}
  39. set{ any = value;}
  40. }
  41. //Undocumented property
  42. [XmlIgnore]
  43. public XmlSchemaAttributeGroup RedefinedAttributeGroup
  44. {
  45. get{ return redefined;}
  46. }
  47. [XmlIgnore]
  48. internal XmlQualifiedName QualifiedName
  49. {
  50. get{ return qualifiedName;}
  51. }
  52. /// <remarks>
  53. /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
  54. /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
  55. /// 1. Name must be present
  56. /// </remarks>
  57. [MonoTODO]
  58. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  59. {
  60. errorCount = 0;
  61. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  62. if(this.Name == null) //1
  63. error(h,"Name is required in top level simpletype");
  64. else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
  65. error(h,"name attribute of a simpleType must be NCName");
  66. else
  67. this.qualifiedName = new XmlQualifiedName(this.Name,info.TargetNamespace);
  68. if(this.AnyAttribute != null)
  69. {
  70. errorCount += this.AnyAttribute.Compile(h,info);
  71. }
  72. foreach(XmlSchemaObject obj in Attributes)
  73. {
  74. if(obj is XmlSchemaAttribute)
  75. {
  76. XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
  77. errorCount += attr.Compile(h, info);
  78. }
  79. else if(obj is XmlSchemaAttributeGroupRef)
  80. {
  81. XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;
  82. errorCount += gref.Compile(h, info);
  83. }
  84. else
  85. {
  86. error(h,"invalid type of object in Attributes property");
  87. }
  88. }
  89. return errorCount;
  90. }
  91. [MonoTODO]
  92. internal int Validate(ValidationEventHandler h)
  93. {
  94. return errorCount;
  95. }
  96. //<attributeGroup
  97. // id = ID
  98. // name = NCName
  99. // ref = QName // Not present in this class.
  100. // {any attributes with non-schema namespace . . .}>
  101. // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  102. //</attributeGroup>
  103. internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
  104. {
  105. XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();
  106. reader.MoveToElement();
  107. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  108. {
  109. error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
  110. reader.SkipToEnd();
  111. return null;
  112. }
  113. attrgrp.LineNumber = reader.LineNumber;
  114. attrgrp.LinePosition = reader.LinePosition;
  115. attrgrp.SourceUri = reader.BaseURI;
  116. while(reader.MoveToNextAttribute())
  117. {
  118. if(reader.Name == "id")
  119. {
  120. attrgrp.Id = reader.Value;
  121. }
  122. else if(reader.Name == "name")
  123. {
  124. attrgrp.name = reader.Value;
  125. }
  126. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  127. {
  128. error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
  129. }
  130. else
  131. {
  132. XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
  133. }
  134. }
  135. reader.MoveToElement();
  136. if(reader.IsEmptyElement)
  137. return attrgrp;
  138. //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
  139. int level = 1;
  140. while(reader.ReadNextElement())
  141. {
  142. if(reader.NodeType == XmlNodeType.EndElement)
  143. {
  144. if(reader.LocalName != xmlname)
  145. error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
  146. break;
  147. }
  148. if(level <= 1 && reader.LocalName == "annotation")
  149. {
  150. level = 2; //Only one annotation
  151. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  152. if(annotation != null)
  153. attrgrp.Annotation = annotation;
  154. continue;
  155. }
  156. if(level <= 2)
  157. {
  158. if(reader.LocalName == "attribute")
  159. {
  160. level = 2;
  161. XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
  162. if(attr != null)
  163. attrgrp.Attributes.Add(attr);
  164. continue;
  165. }
  166. if(reader.LocalName == "attributeGroup")
  167. {
  168. level = 2;
  169. XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
  170. if(attr != null)
  171. attrgrp.attributes.Add(attr);
  172. continue;
  173. }
  174. }
  175. if(level <= 3 && reader.LocalName == "anyAttribute")
  176. {
  177. level = 4;
  178. XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
  179. if(anyattr != null)
  180. attrgrp.AnyAttribute = anyattr;
  181. continue;
  182. }
  183. reader.RaiseInvalidElementError();
  184. }
  185. return attrgrp;
  186. }
  187. }
  188. }