XmlSchemaAnnotation.cs 4.0 KB

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