XmlSchemaAttributeGroupRef.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /// </remarks>
  33. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  34. {
  35. // If this is already compiled this time, simply skip.
  36. if (this.IsComplied (schema.CompilationId))
  37. return 0;
  38. errorCount = 0;
  39. if(RefName == null || RefName.IsEmpty)
  40. error(h, "ref must be present");
  41. else if(!XmlSchemaUtil.CheckQName(RefName))
  42. error(h, "ref must be a valid qname");
  43. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  44. this.CompilationId = schema.CompilationId;
  45. return errorCount;
  46. }
  47. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  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. }