XmlSchemaAnnotation.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Collections;
  5. using System.Xml;
  6. using System.Xml.Serialization;
  7. namespace System.Xml.Schema
  8. {
  9. /// <summary>
  10. /// Summary description for XmlSchemaAnnotation.
  11. /// </summary>
  12. public class XmlSchemaAnnotation : XmlSchemaObject
  13. {
  14. private string id;
  15. private XmlSchemaObjectCollection items;
  16. private XmlAttribute[] unhandledAttributes;
  17. const string xmlname = "annotation";
  18. public XmlSchemaAnnotation()
  19. {
  20. items = new XmlSchemaObjectCollection();
  21. }
  22. [System.Xml.Serialization.XmlAttribute("id")]
  23. public string Id
  24. {
  25. get{ return id; }
  26. set{ id = value; }
  27. }
  28. [XmlElement("appinfo",typeof(XmlSchemaAppInfo),Namespace=XmlSchema.Namespace)]
  29. [XmlElement("documentation",typeof(XmlSchemaDocumentation),Namespace=XmlSchema.Namespace)]
  30. public XmlSchemaObjectCollection Items
  31. {
  32. get{ return items; }
  33. }
  34. [XmlAnyAttribute]
  35. public XmlAttribute[] UnhandledAttributes
  36. {
  37. get
  38. {
  39. if(unhandledAttributeList != null)
  40. {
  41. unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
  42. unhandledAttributeList = null;
  43. }
  44. return unhandledAttributes;
  45. }
  46. set
  47. {
  48. unhandledAttributes = value;
  49. unhandledAttributeList = null;
  50. }
  51. }
  52. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  53. {
  54. // If this is already compiled this time, simply skip.
  55. if (this.IsComplied (schema.CompilationId))
  56. return 0;
  57. this.CompilationId = schema.CompilationId;
  58. return 0;
  59. }
  60. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  61. {
  62. return 0;
  63. }
  64. //<annotation
  65. // id = ID
  66. // {any attributes with non-schema namespace . . .}>
  67. // Content: (appinfo | documentation)*
  68. //</annotation>
  69. internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
  70. {
  71. XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
  72. reader.MoveToElement();
  73. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  74. {
  75. error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
  76. reader.SkipToEnd();
  77. return null;
  78. }
  79. annotation.LineNumber = reader.LineNumber;
  80. annotation.LinePosition = reader.LinePosition;
  81. annotation.SourceUri = reader.BaseURI;
  82. //Read Attributes
  83. while(reader.MoveToNextAttribute())
  84. {
  85. if(reader.Name == "id")
  86. {
  87. annotation.Id = reader.Value;
  88. }
  89. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  90. {
  91. error(h,reader.Name + " is not a valid attribute for annotation",null);
  92. }
  93. else
  94. {
  95. XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
  96. }
  97. }
  98. reader.MoveToElement();
  99. if(reader.IsEmptyElement)
  100. return annotation;
  101. //Content: (appinfo | documentation)*
  102. bool skip = false;
  103. string expectedEnd = null;
  104. while(!reader.EOF)
  105. {
  106. if(skip)
  107. skip=false;
  108. else
  109. reader.ReadNextElement();
  110. if(reader.NodeType == XmlNodeType.EndElement)
  111. {
  112. bool end = true;
  113. string expected = xmlname;
  114. if(expectedEnd != null)
  115. {
  116. expected = expectedEnd;
  117. expectedEnd = null;
  118. end = false;
  119. }
  120. if(reader.LocalName != expected)
  121. error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
  122. if (end)
  123. break;
  124. else
  125. continue;
  126. }
  127. if(reader.LocalName == "appinfo")
  128. {
  129. XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
  130. if(appinfo != null)
  131. annotation.items.Add(appinfo);
  132. continue;
  133. }
  134. if(reader.LocalName == "documentation")
  135. {
  136. XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
  137. if(documentation != null)
  138. annotation.items.Add(documentation);
  139. continue;
  140. }
  141. reader.RaiseInvalidElementError();
  142. }
  143. return annotation;
  144. }
  145. }
  146. }