XmlSchemaAttributeGroupRef.cs 3.5 KB

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