XmlSchemaAttributeGroupRef.cs 3.6 KB

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