XmlSchemaNotation.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.Xml.Serialization;
  25. using System.Xml;
  26. namespace System.Xml.Schema
  27. {
  28. /// <summary>
  29. /// Summary description for XmlSchemaNotation.
  30. /// </summary>
  31. public class XmlSchemaNotation : XmlSchemaAnnotated
  32. {
  33. private string name;
  34. private string pub;
  35. private string system;
  36. private XmlQualifiedName qualifiedName;
  37. const string xmlname = "notation";
  38. public XmlSchemaNotation()
  39. {
  40. }
  41. [System.Xml.Serialization.XmlAttribute("name")]
  42. public string Name
  43. {
  44. get{ return name; }
  45. set{ name = value; }
  46. }
  47. [System.Xml.Serialization.XmlAttribute("public")]
  48. public string Public
  49. {
  50. get{ return pub; }
  51. set{ pub = value; }
  52. }
  53. [System.Xml.Serialization.XmlAttribute("system")]
  54. public string System
  55. {
  56. get{ return system; }
  57. set{ system = value; }
  58. }
  59. [XmlIgnore]
  60. internal XmlQualifiedName QualifiedName
  61. {
  62. get{ return qualifiedName;}
  63. }
  64. // 1. name and public must be present
  65. // public and system must be anyURI
  66. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  67. {
  68. // If this is already compiled this time, simply skip.
  69. if (this.IsComplied (schema.CompilationId))
  70. return 0;
  71. if(Name == null)
  72. error(h,"Required attribute name must be present");
  73. else if(!XmlSchemaUtil.CheckNCName(this.name))
  74. error(h,"attribute name must be NCName");
  75. else
  76. qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace);
  77. if(Public==null)
  78. error(h,"public must be present");
  79. else if(!XmlSchemaUtil.CheckAnyUri(Public))
  80. error(h,"public must be anyURI");
  81. if(system != null && !XmlSchemaUtil.CheckAnyUri(system))
  82. error(h,"system must be present and of Type anyURI");
  83. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  84. return errorCount;
  85. }
  86. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  87. {
  88. return errorCount;
  89. }
  90. //<notation
  91. // id = ID
  92. // name = NCName
  93. // public = anyURI
  94. // system = anyURI
  95. // {any attributes with non-schema namespace . . .}>
  96. // Content: (annotation?)
  97. //</notation>
  98. internal static XmlSchemaNotation Read(XmlSchemaReader reader, ValidationEventHandler h)
  99. {
  100. XmlSchemaNotation notation = new XmlSchemaNotation();
  101. reader.MoveToElement();
  102. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  103. {
  104. error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);
  105. reader.Skip();
  106. return null;
  107. }
  108. notation.LineNumber = reader.LineNumber;
  109. notation.LinePosition = reader.LinePosition;
  110. notation.SourceUri = reader.BaseURI;
  111. while(reader.MoveToNextAttribute())
  112. {
  113. if(reader.Name == "id")
  114. {
  115. notation.Id = reader.Value;
  116. }
  117. else if(reader.Name == "name")
  118. {
  119. notation.name = reader.Value;
  120. }
  121. else if(reader.Name == "public")
  122. {
  123. notation.pub = reader.Value;
  124. }
  125. else if(reader.Name == "system")
  126. {
  127. notation.system = reader.Value;
  128. }
  129. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  130. {
  131. error(h,reader.Name + " is not a valid attribute for notation",null);
  132. }
  133. else
  134. {
  135. XmlSchemaUtil.ReadUnhandledAttribute(reader,notation);
  136. }
  137. }
  138. reader.MoveToElement();
  139. if(reader.IsEmptyElement)
  140. return notation;
  141. // Content: (annotation?)
  142. int level = 1;
  143. while(reader.ReadNextElement())
  144. {
  145. if(reader.NodeType == XmlNodeType.EndElement)
  146. {
  147. if(reader.LocalName != xmlname)
  148. error(h,"Should not happen :2: XmlSchemaNotation.Read, name="+reader.Name,null);
  149. break;
  150. }
  151. if(level <= 1 && reader.LocalName == "annotation")
  152. {
  153. level = 2; //Only one annotation
  154. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  155. if(annotation != null)
  156. notation.Annotation = annotation;
  157. continue;
  158. }
  159. reader.RaiseInvalidElementError();
  160. }
  161. return notation;
  162. }
  163. }
  164. }