XmlSchemaIdentityConstraint.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaIdentityConstraint.
  10. /// </summary>
  11. public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
  12. {
  13. private XmlSchemaObjectCollection fields;
  14. private string name;
  15. private XmlQualifiedName qName;
  16. private XmlSchemaXPath selector;
  17. public XmlSchemaIdentityConstraint()
  18. {
  19. fields = new XmlSchemaObjectCollection();
  20. qName = XmlQualifiedName.Empty;
  21. }
  22. [System.Xml.Serialization.XmlAttribute("name")]
  23. public string Name
  24. {
  25. get{ return name; }
  26. set{ name = value; }
  27. }
  28. [XmlElement("selector",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
  29. public XmlSchemaXPath Selector
  30. {
  31. get{ return selector; }
  32. set{ selector = value; }
  33. }
  34. [XmlElement("field",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
  35. public XmlSchemaObjectCollection Fields
  36. {
  37. get{ return fields; }
  38. }
  39. [XmlIgnore]
  40. public XmlQualifiedName QualifiedName
  41. {
  42. get{ return qName; }
  43. }
  44. /// <remarks>
  45. /// 1. name must be present
  46. /// 2. selector and field must be present
  47. /// </remarks>
  48. [MonoTODO]
  49. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  50. {
  51. // If this is already compiled this time, simply skip.
  52. if (this.IsComplied (schema.CompilationId))
  53. return 0;
  54. if(Name == null)
  55. error(h,"Required attribute name must be present");
  56. else if(!XmlSchemaUtil.CheckNCName(this.name))
  57. error(h,"attribute name must be NCName");
  58. else
  59. this.qName = new XmlQualifiedName(Name,schema.TargetNamespace);
  60. if(Selector == null)
  61. error(h,"selector must be present");
  62. else
  63. {
  64. errorCount += Selector.Compile(h,schema);
  65. }
  66. if(Fields.Count == 0)
  67. error(h,"atleast one field value must be present");
  68. else
  69. {
  70. foreach(XmlSchemaObject obj in Fields)
  71. {
  72. if(obj is XmlSchemaXPath)
  73. {
  74. XmlSchemaXPath field = (XmlSchemaXPath)obj;
  75. errorCount += field.Compile(h,schema);
  76. }
  77. else
  78. error(h,"Object of type "+obj.GetType()+" is invalid in the Fields Collection");
  79. }
  80. }
  81. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  82. this.CompilationId = schema.CompilationId;
  83. return errorCount;
  84. }
  85. }
  86. }