XmlSchemaNotation.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. [MonoTODO]
  47. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  48. {
  49. // If this is already compiled this time, simply skip.
  50. if (this.IsComplied (schema.CompilationId))
  51. return 0;
  52. if(Name == null)
  53. error(h,"Required attribute name must be present");
  54. else if(!XmlSchemaUtil.CheckNCName(this.name))
  55. error(h,"attribute name must be NCName");
  56. else
  57. qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace);
  58. if(Public==null)
  59. error(h,"public must be present");
  60. else if(!XmlSchemaUtil.CheckAnyUri(Public))
  61. error(h,"public must be anyURI");
  62. if(system != null && !XmlSchemaUtil.CheckAnyUri(system))
  63. error(h,"system must be present and of Type anyURI");
  64. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  65. return errorCount;
  66. }
  67. [MonoTODO]
  68. internal int Validate(ValidationEventHandler h)
  69. {
  70. return errorCount;
  71. }
  72. //<notation
  73. // id = ID
  74. // name = NCName
  75. // public = anyURI
  76. // system = anyURI
  77. // {any attributes with non-schema namespace . . .}>
  78. // Content: (annotation?)
  79. //</notation>
  80. internal static XmlSchemaNotation Read(XmlSchemaReader reader, ValidationEventHandler h)
  81. {
  82. XmlSchemaNotation notation = new XmlSchemaNotation();
  83. reader.MoveToElement();
  84. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  85. {
  86. error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);
  87. reader.Skip();
  88. return null;
  89. }
  90. notation.LineNumber = reader.LineNumber;
  91. notation.LinePosition = reader.LinePosition;
  92. notation.SourceUri = reader.BaseURI;
  93. while(reader.MoveToNextAttribute())
  94. {
  95. if(reader.Name == "id")
  96. {
  97. notation.Id = reader.Value;
  98. }
  99. else if(reader.Name == "name")
  100. {
  101. notation.name = reader.Value;
  102. }
  103. else if(reader.Name == "public")
  104. {
  105. notation.pub = reader.Value;
  106. }
  107. else if(reader.Name == "system")
  108. {
  109. notation.system = reader.Value;
  110. }
  111. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  112. {
  113. error(h,reader.Name + " is not a valid attribute for notation",null);
  114. }
  115. else
  116. {
  117. XmlSchemaUtil.ReadUnhandledAttribute(reader,notation);
  118. }
  119. }
  120. reader.MoveToElement();
  121. if(reader.IsEmptyElement)
  122. return notation;
  123. // Content: (annotation?)
  124. int level = 1;
  125. while(reader.ReadNextElement())
  126. {
  127. if(reader.NodeType == XmlNodeType.EndElement)
  128. {
  129. if(reader.LocalName != xmlname)
  130. error(h,"Should not happen :2: XmlSchemaNotation.Read, name="+reader.Name,null);
  131. break;
  132. }
  133. if(level <= 1 && reader.LocalName == "annotation")
  134. {
  135. level = 2; //Only one annotation
  136. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  137. if(annotation != null)
  138. notation.Annotation = annotation;
  139. continue;
  140. }
  141. reader.RaiseInvalidElementError();
  142. }
  143. return notation;
  144. }
  145. }
  146. }