XmlSchemaAnnotation.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Collections;
  25. using System.Xml;
  26. using System.Xml.Serialization;
  27. namespace System.Xml.Schema
  28. {
  29. /// <summary>
  30. /// Summary description for XmlSchemaAnnotation.
  31. /// </summary>
  32. public class XmlSchemaAnnotation : XmlSchemaObject
  33. {
  34. private string id;
  35. private XmlSchemaObjectCollection items;
  36. private XmlAttribute[] unhandledAttributes;
  37. const string xmlname = "annotation";
  38. public XmlSchemaAnnotation()
  39. {
  40. items = new XmlSchemaObjectCollection();
  41. }
  42. [System.Xml.Serialization.XmlAttribute("id", DataType="ID")]
  43. public string Id
  44. {
  45. get{ return id; }
  46. set{ id = value; }
  47. }
  48. [XmlElement("appinfo",typeof(XmlSchemaAppInfo))]
  49. [XmlElement("documentation",typeof(XmlSchemaDocumentation))]
  50. public XmlSchemaObjectCollection Items
  51. {
  52. get{ return items; }
  53. }
  54. [XmlAnyAttribute]
  55. public XmlAttribute[] UnhandledAttributes
  56. {
  57. get
  58. {
  59. if(unhandledAttributeList != null)
  60. {
  61. unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
  62. unhandledAttributeList = null;
  63. }
  64. return unhandledAttributes;
  65. }
  66. set
  67. {
  68. unhandledAttributes = value;
  69. unhandledAttributeList = null;
  70. }
  71. }
  72. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  73. {
  74. // If this is already compiled this time, simply skip.
  75. if (this.IsComplied (schema.CompilationId))
  76. return 0;
  77. this.CompilationId = schema.CompilationId;
  78. return 0;
  79. }
  80. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  81. {
  82. return 0;
  83. }
  84. //<annotation
  85. // id = ID
  86. // {any attributes with non-schema namespace . . .}>
  87. // Content: (appinfo | documentation)*
  88. //</annotation>
  89. internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
  90. {
  91. XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
  92. reader.MoveToElement();
  93. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  94. {
  95. error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
  96. reader.SkipToEnd();
  97. return null;
  98. }
  99. annotation.LineNumber = reader.LineNumber;
  100. annotation.LinePosition = reader.LinePosition;
  101. annotation.SourceUri = reader.BaseURI;
  102. //Read Attributes
  103. while(reader.MoveToNextAttribute())
  104. {
  105. if(reader.Name == "id")
  106. {
  107. annotation.Id = reader.Value;
  108. }
  109. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  110. {
  111. error(h,reader.Name + " is not a valid attribute for annotation",null);
  112. }
  113. else
  114. {
  115. XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
  116. }
  117. }
  118. reader.MoveToElement();
  119. if(reader.IsEmptyElement)
  120. return annotation;
  121. //Content: (appinfo | documentation)*
  122. bool skip = false;
  123. string expectedEnd = null;
  124. while(!reader.EOF)
  125. {
  126. if(skip)
  127. skip=false;
  128. else
  129. reader.ReadNextElement();
  130. if(reader.NodeType == XmlNodeType.EndElement)
  131. {
  132. bool end = true;
  133. string expected = xmlname;
  134. if(expectedEnd != null)
  135. {
  136. expected = expectedEnd;
  137. expectedEnd = null;
  138. end = false;
  139. }
  140. if(reader.LocalName != expected)
  141. error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
  142. if (end)
  143. break;
  144. else
  145. continue;
  146. }
  147. if(reader.LocalName == "appinfo")
  148. {
  149. XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
  150. if(appinfo != null)
  151. annotation.items.Add(appinfo);
  152. continue;
  153. }
  154. if(reader.LocalName == "documentation")
  155. {
  156. XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
  157. if(documentation != null)
  158. annotation.items.Add(documentation);
  159. continue;
  160. }
  161. reader.RaiseInvalidElementError();
  162. }
  163. return annotation;
  164. }
  165. }
  166. }