XmlSchemaIdentityConstraint.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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="http://www.w3.org/2001/XMLSchema")]
  29. public XmlSchemaXPath Selector
  30. {
  31. get{ return selector; }
  32. set{ selector = value; }
  33. }
  34. [XmlElement("field",typeof(XmlSchemaXPath),Namespace="http://www.w3.org/2001/XMLSchema")]
  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, XmlSchemaInfo info)
  50. {
  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. this.qName = new XmlQualifiedName(Name,info.TargetNamespace);
  57. if(Selector == null)
  58. error(h,"selector must be present");
  59. else
  60. {
  61. errorCount += Selector.Compile(h,info);
  62. }
  63. if(Fields.Count == 0)
  64. error(h,"atleast one field value must be present");
  65. else
  66. {
  67. foreach(XmlSchemaObject obj in Fields)
  68. {
  69. if(obj is XmlSchemaXPath)
  70. {
  71. XmlSchemaXPath field = (XmlSchemaXPath)obj;
  72. errorCount += field.Compile(h,info);
  73. }
  74. else
  75. error(h,"Object of type "+obj.GetType()+" is invalid in the Fields Collection");
  76. }
  77. }
  78. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  79. return errorCount;
  80. }
  81. }
  82. }