XmlSchemaAnnotation.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. while(!reader.EOF)
  102. {
  103. if(skip)
  104. skip=false;
  105. else
  106. reader.ReadNextElement();
  107. if(reader.NodeType == XmlNodeType.EndElement)
  108. {
  109. if(reader.LocalName != xmlname)
  110. error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name,null);
  111. break;
  112. }
  113. if(reader.LocalName == "appinfo")
  114. {
  115. XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
  116. if(appinfo != null)
  117. annotation.items.Add(appinfo);
  118. continue;
  119. }
  120. if(reader.LocalName == "documentation")
  121. {
  122. XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
  123. if(documentation != null)
  124. annotation.items.Add(documentation);
  125. continue;
  126. }
  127. reader.RaiseInvalidElementError();
  128. }
  129. return annotation;
  130. }
  131. }
  132. }