XmlSchemaAny.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. using System.ComponentModel;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaAny.
  10. /// </summary>
  11. public class XmlSchemaAny : XmlSchemaParticle
  12. {
  13. private string nameSpace;
  14. private XmlSchemaContentProcessing processing;
  15. private int errorCount = 0;
  16. public XmlSchemaAny()
  17. {
  18. }
  19. [System.Xml.Serialization.XmlAttribute("namespace")]
  20. public string Namespace
  21. {
  22. get{ return nameSpace; }
  23. set{ nameSpace = value; }
  24. }
  25. [DefaultValue(XmlSchemaContentProcessing.None)]
  26. [System.Xml.Serialization.XmlAttribute("processContents")]
  27. public XmlSchemaContentProcessing ProcessContents
  28. {
  29. get{ return processing; }
  30. set{ processing = value; }
  31. }
  32. /// <remarks>
  33. /// 1. id must be of type ID
  34. /// 2. namespace can have one of the following values:
  35. /// a) ##any or ##other
  36. /// b) list of anyURI and ##targetNamespace and ##local
  37. /// </remarks>
  38. [MonoTODO]
  39. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  40. {
  41. errorCount = 0;
  42. if(Id != null && !XmlSchemaUtil.CheckID(Id))
  43. {
  44. error(h, "id attribute must be a valid ID");
  45. }
  46. //define ##any=1,##other=2,##targetNamespace=4,##local=8,anyURI=16
  47. int nscount = 0;
  48. string[] nslist = XmlSchemaUtil.SplitList(Namespace);
  49. foreach(string ns in nslist)
  50. {
  51. switch(ns)
  52. {
  53. case "##any":
  54. nscount |= 1;
  55. break;
  56. case "##other":
  57. nscount |= 2;
  58. break;
  59. case "##targetNamespace":
  60. nscount |= 4;
  61. break;
  62. case "##local":
  63. nscount |= 8;
  64. break;
  65. default:
  66. if(!XmlSchemaUtil.CheckAnyUri(ns))
  67. error(h,"the namespace is not a valid anyURI");
  68. else
  69. nscount |= 16;
  70. break;
  71. }
  72. }
  73. if((nscount&1) == 1 && nscount != 1)
  74. error(h,"##any if present must be the only namespace attribute");
  75. if((nscount&2) == 2 && nscount != 2)
  76. error(h,"##other if present must be the only namespace attribute");
  77. return errorCount;
  78. }
  79. [MonoTODO]
  80. internal int Validate(ValidationEventHandler h)
  81. {
  82. return errorCount;
  83. }
  84. internal void error(ValidationEventHandler handle,string message)
  85. {
  86. errorCount++;
  87. ValidationHandler.RaiseValidationError(handle,this,message);
  88. }
  89. }
  90. }