XmlSchemaNotation.cs 4.1 KB

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