XmlSchemaAnnotation.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. private static 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. [MonoTODO]
  53. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  54. {
  55. // If this is already compiled this time, simply skip.
  56. if (this.IsComplied (schema.CompilationId))
  57. return 0;
  58. this.CompilationId = schema.CompilationId;
  59. return 0;
  60. }
  61. [MonoTODO]
  62. internal int Validate(ValidationEventHandler h)
  63. {
  64. return 0;
  65. }
  66. //<annotation
  67. // id = ID
  68. // {any attributes with non-schema namespace . . .}>
  69. // Content: (appinfo | documentation)*
  70. //</annotation>
  71. internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
  72. {
  73. XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
  74. reader.MoveToElement();
  75. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  76. {
  77. error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
  78. reader.SkipToEnd();
  79. return null;
  80. }
  81. annotation.LineNumber = reader.LineNumber;
  82. annotation.LinePosition = reader.LinePosition;
  83. annotation.SourceUri = reader.BaseURI;
  84. //Read Attributes
  85. while(reader.MoveToNextAttribute())
  86. {
  87. if(reader.Name == "id")
  88. {
  89. annotation.Id = reader.Value;
  90. }
  91. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  92. {
  93. error(h,reader.Name + " is not a valid attribute for annotation",null);
  94. }
  95. else
  96. {
  97. XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
  98. }
  99. }
  100. reader.MoveToElement();
  101. if(reader.IsEmptyElement)
  102. return annotation;
  103. //Content: (appinfo | documentation)*
  104. bool skip = false;
  105. string expectedEnd = null;
  106. while(!reader.EOF)
  107. {
  108. if(skip)
  109. skip=false;
  110. else
  111. reader.ReadNextElement();
  112. if(reader.NodeType == XmlNodeType.EndElement)
  113. {
  114. bool end = true;
  115. string expected = xmlname;
  116. if(expectedEnd != null)
  117. {
  118. expected = expectedEnd;
  119. expectedEnd = null;
  120. end = false;
  121. }
  122. if(reader.LocalName != expected)
  123. error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
  124. if (end)
  125. break;
  126. else
  127. continue;
  128. }
  129. if(reader.LocalName == "appinfo")
  130. {
  131. XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
  132. if(appinfo != null)
  133. annotation.items.Add(appinfo);
  134. continue;
  135. }
  136. if(reader.LocalName == "documentation")
  137. {
  138. XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
  139. if(documentation != null)
  140. annotation.items.Add(documentation);
  141. continue;
  142. }
  143. reader.RaiseInvalidElementError();
  144. }
  145. return annotation;
  146. }
  147. }
  148. }