XmlSchemaAttributeGroupRef.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. private static 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. [MonoTODO]
  35. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  36. {
  37. // If this is already compiled this time, simply skip.
  38. if (this.IsComplied (schema.CompilationId))
  39. return 0;
  40. errorCount = 0;
  41. if(RefName == null || RefName.IsEmpty)
  42. error(h, "ref must be present");
  43. else if(!XmlSchemaUtil.CheckQName(RefName))
  44. error(h, "ref must be a valid qname");
  45. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  46. // if(this.Annotation != null)
  47. // error(h, "attributegroup with a ref can't have any content");
  48. this.CompilationId = schema.CompilationId;
  49. return errorCount;
  50. }
  51. [MonoTODO]
  52. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  53. {
  54. return errorCount;
  55. }
  56. //<attributeGroup
  57. // id = ID
  58. // ref = QName
  59. // {any attributes with non-schema namespace . . .}>
  60. // Content: (annotation?)
  61. //</attributeGroup>
  62. internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
  63. {
  64. XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();
  65. reader.MoveToElement();
  66. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  67. {
  68. error(h,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  69. reader.SkipToEnd();
  70. return null;
  71. }
  72. attrgrp.LineNumber = reader.LineNumber;
  73. attrgrp.LinePosition = reader.LinePosition;
  74. attrgrp.SourceUri = reader.BaseURI;
  75. while(reader.MoveToNextAttribute())
  76. {
  77. if(reader.Name == "id")
  78. {
  79. attrgrp.Id = reader.Value;
  80. }
  81. else if(reader.Name == "ref")
  82. {
  83. Exception innerex;
  84. attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  85. if(innerex != null)
  86. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  87. }
  88. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  89. {
  90. error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
  91. }
  92. else
  93. {
  94. XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
  95. }
  96. }
  97. reader.MoveToElement();
  98. if(reader.IsEmptyElement)
  99. return attrgrp;
  100. int level = 1;
  101. while(reader.ReadNextElement())
  102. {
  103. if(reader.NodeType == XmlNodeType.EndElement)
  104. {
  105. if(reader.LocalName != xmlname)
  106. error(h,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  107. break;
  108. }
  109. if(level <= 1 && reader.LocalName == "annotation")
  110. {
  111. level = 2; //Only one annotation
  112. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  113. if(annotation != null)
  114. attrgrp.Annotation = annotation;
  115. continue;
  116. }
  117. reader.RaiseInvalidElementError();
  118. }
  119. return attrgrp;
  120. }
  121. }
  122. }