XmlSchemaUnique.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. namespace System.Xml.Schema
  6. {
  7. /// <summary>
  8. /// Summary description for XmlSchemaUnique.
  9. /// </summary>
  10. public class XmlSchemaUnique : XmlSchemaIdentityConstraint
  11. {
  12. private static string xmlname = "unique";
  13. public XmlSchemaUnique()
  14. {
  15. }
  16. /// <remarks>
  17. /// 1. name must be present
  18. /// 2. selector and field must be present
  19. /// </remarks>
  20. [MonoTODO]
  21. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  22. {
  23. return base.Compile(h,schema);
  24. }
  25. [MonoTODO]
  26. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  27. {
  28. return errorCount;
  29. }
  30. /*
  31. internal new void error(ValidationEventHandler handle, string message)
  32. {
  33. errorCount++;
  34. ValidationHandler.RaiseValidationError(handle, this, message);
  35. }
  36. */
  37. //<unique
  38. // id = ID
  39. // name = NCName
  40. // {any attributes with non-schema namespace . . .}>
  41. // Content: (annotation?, (selector, field+))
  42. //</unique>
  43. internal static XmlSchemaUnique Read(XmlSchemaReader reader, ValidationEventHandler h)
  44. {
  45. XmlSchemaUnique unique = new XmlSchemaUnique();
  46. reader.MoveToElement();
  47. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  48. {
  49. error(h,"Should not happen :1: XmlSchemaUnique.Read, name="+reader.Name,null);
  50. reader.Skip();
  51. return null;
  52. }
  53. unique.LineNumber = reader.LineNumber;
  54. unique.LinePosition = reader.LinePosition;
  55. unique.SourceUri = reader.BaseURI;
  56. while(reader.MoveToNextAttribute())
  57. {
  58. if(reader.Name == "id")
  59. {
  60. unique.Id = reader.Value;
  61. }
  62. else if(reader.Name == "name")
  63. {
  64. unique.Name = reader.Value;
  65. }
  66. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  67. {
  68. error(h,reader.Name + " is not a valid attribute for unique",null);
  69. }
  70. else
  71. {
  72. XmlSchemaUtil.ReadUnhandledAttribute(reader,unique);
  73. }
  74. }
  75. reader.MoveToElement();
  76. if(reader.IsEmptyElement)
  77. return unique;
  78. // Content: annotation?, selector, field+
  79. int level = 1;
  80. while(reader.ReadNextElement())
  81. {
  82. if(reader.NodeType == XmlNodeType.EndElement)
  83. {
  84. if(reader.LocalName != xmlname)
  85. error(h,"Should not happen :2: XmlSchemaUnion.Read, name="+reader.Name,null);
  86. break;
  87. }
  88. if(level <= 1 && reader.LocalName == "annotation")
  89. {
  90. level = 2; //Only one annotation
  91. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  92. if(annotation != null)
  93. unique.Annotation = annotation;
  94. continue;
  95. }
  96. if(level <= 2 && reader.LocalName == "selector")
  97. {
  98. level = 3;
  99. XmlSchemaXPath selector = XmlSchemaXPath.Read(reader,h,"selector");
  100. if(selector != null)
  101. unique.Selector = selector;
  102. continue;
  103. }
  104. if(level <= 3 && reader.LocalName == "field")
  105. {
  106. level = 3;
  107. if(unique.Selector == null)
  108. error(h,"selector must be defined before field declarations",null);
  109. XmlSchemaXPath field = XmlSchemaXPath.Read(reader,h,"field");
  110. if(field != null)
  111. unique.Fields.Add(field);
  112. continue;
  113. }
  114. reader.RaiseInvalidElementError();
  115. }
  116. return unique;
  117. }
  118. }
  119. }