XmlSchemaNotation.cs 4.0 KB

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