XmlSchemaAttributeGroupRef.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // System.Xml.Schema.XmlSchemaAttributeGroupRef.cs
  3. //
  4. // Author:
  5. // Dwivedi, Ajay kumar [email protected]
  6. // Atsushi Enomoto [email protected]
  7. //
  8. using System;
  9. using System.Xml;
  10. using System.Xml.Serialization;
  11. namespace System.Xml.Schema
  12. {
  13. /// <summary>
  14. /// Summary description for XmlSchemaAttributeGroupRef.
  15. /// </summary>
  16. public class XmlSchemaAttributeGroupRef : XmlSchemaAnnotated
  17. {
  18. private XmlQualifiedName refName;
  19. const string xmlname = "attributeGroup";
  20. public XmlSchemaAttributeGroupRef()
  21. {
  22. refName = XmlQualifiedName.Empty;
  23. }
  24. [System.Xml.Serialization.XmlAttribute("ref")]
  25. public XmlQualifiedName RefName
  26. {
  27. get{ return refName; }
  28. set{ refName = value; }
  29. }
  30. /// <remarks>
  31. /// 1. ref must be present
  32. /// 2. The element must be empty. ?? FIXME: Is this correct or annotation is permitted?
  33. /// </remarks>
  34. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  35. {
  36. // If this is already compiled this time, simply skip.
  37. if (this.IsComplied (schema.CompilationId))
  38. return 0;
  39. errorCount = 0;
  40. if(RefName == null || RefName.IsEmpty)
  41. error(h, "ref must be present");
  42. else if(!XmlSchemaUtil.CheckQName(RefName))
  43. error(h, "ref must be a valid qname");
  44. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  45. // if(this.Annotation != null)
  46. // error(h, "attributegroup with a ref can't have any content");
  47. this.CompilationId = schema.CompilationId;
  48. return errorCount;
  49. }
  50. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  51. {
  52. return errorCount;
  53. }
  54. //<attributeGroup
  55. // id = ID
  56. // ref = QName
  57. // {any attributes with non-schema namespace . . .}>
  58. // Content: (annotation?)
  59. //</attributeGroup>
  60. internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
  61. {
  62. XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();
  63. reader.MoveToElement();
  64. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  65. {
  66. error(h,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  67. reader.SkipToEnd();
  68. return null;
  69. }
  70. attrgrp.LineNumber = reader.LineNumber;
  71. attrgrp.LinePosition = reader.LinePosition;
  72. attrgrp.SourceUri = reader.BaseURI;
  73. while(reader.MoveToNextAttribute())
  74. {
  75. if(reader.Name == "id")
  76. {
  77. attrgrp.Id = reader.Value;
  78. }
  79. else if(reader.Name == "ref")
  80. {
  81. Exception innerex;
  82. attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  83. if(innerex != null)
  84. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  85. }
  86. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  87. {
  88. error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
  89. }
  90. else
  91. {
  92. XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
  93. }
  94. }
  95. reader.MoveToElement();
  96. if(reader.IsEmptyElement)
  97. return attrgrp;
  98. int level = 1;
  99. while(reader.ReadNextElement())
  100. {
  101. if(reader.NodeType == XmlNodeType.EndElement)
  102. {
  103. if(reader.LocalName != xmlname)
  104. error(h,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  105. break;
  106. }
  107. if(level <= 1 && reader.LocalName == "annotation")
  108. {
  109. level = 2; //Only one annotation
  110. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  111. if(annotation != null)
  112. attrgrp.Annotation = annotation;
  113. continue;
  114. }
  115. reader.RaiseInvalidElementError();
  116. }
  117. return attrgrp;
  118. }
  119. }
  120. }