2
0

XmlSchemaAny.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. using System.ComponentModel;
  7. namespace System.Xml.Schema
  8. {
  9. /// <summary>
  10. /// Summary description for XmlSchemaAny.
  11. /// </summary>
  12. public class XmlSchemaAny : XmlSchemaParticle
  13. {
  14. private string nameSpace;
  15. private XmlSchemaContentProcessing processing;
  16. private static string xmlname = "any";
  17. public XmlSchemaAny()
  18. {
  19. }
  20. [System.Xml.Serialization.XmlAttribute("namespace")]
  21. public string Namespace
  22. {
  23. get{ return nameSpace; }
  24. set{ nameSpace = value; }
  25. }
  26. [DefaultValue(XmlSchemaContentProcessing.None)]
  27. [System.Xml.Serialization.XmlAttribute("processContents")]
  28. public XmlSchemaContentProcessing ProcessContents
  29. {
  30. get{ return processing; }
  31. set{ processing = value; }
  32. }
  33. /// <remarks>
  34. /// 1. id must be of type ID
  35. /// 2. namespace can have one of the following values:
  36. /// a) ##any or ##other
  37. /// b) list of anyURI and ##targetNamespace and ##local
  38. /// </remarks>
  39. [MonoTODO]
  40. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  41. {
  42. errorCount = 0;
  43. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  44. //define ##any=1,##other=2,##targetNamespace=4,##local=8,anyURI=16
  45. int nscount = 0;
  46. string[] nslist = XmlSchemaUtil.SplitList(Namespace);
  47. foreach(string ns in nslist)
  48. {
  49. switch(ns)
  50. {
  51. case "##any":
  52. nscount |= 1;
  53. break;
  54. case "##other":
  55. nscount |= 2;
  56. break;
  57. case "##targetNamespace":
  58. nscount |= 4;
  59. break;
  60. case "##local":
  61. nscount |= 8;
  62. break;
  63. default:
  64. if(!XmlSchemaUtil.CheckAnyUri(ns))
  65. error(h,"the namespace is not a valid anyURI");
  66. else
  67. nscount |= 16;
  68. break;
  69. }
  70. }
  71. if((nscount&1) == 1 && nscount != 1)
  72. error(h,"##any if present must be the only namespace attribute");
  73. if((nscount&2) == 2 && nscount != 2)
  74. error(h,"##other if present must be the only namespace attribute");
  75. return errorCount;
  76. }
  77. [MonoTODO]
  78. internal int Validate(ValidationEventHandler h)
  79. {
  80. return errorCount;
  81. }
  82. //<any
  83. // id = ID
  84. // maxOccurs = (nonNegativeInteger | unbounded) : 1
  85. // minOccurs = nonNegativeInteger : 1
  86. // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  87. // processContents = (lax | skip | strict) : strict
  88. // {any attributes with non-schema namespace . . .}>
  89. // Content: (annotation?)
  90. //</any>
  91. internal static XmlSchemaAny Read(XmlSchemaReader reader, ValidationEventHandler h)
  92. {
  93. XmlSchemaAny any = new XmlSchemaAny();
  94. reader.MoveToElement();
  95. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  96. {
  97. error(h,"Should not happen :1: XmlSchemaAny.Read, name="+reader.Name,null);
  98. reader.SkipToEnd();
  99. return null;
  100. }
  101. any.LineNumber = reader.LineNumber;
  102. any.LinePosition = reader.LinePosition;
  103. any.SourceUri = reader.BaseURI;
  104. while(reader.MoveToNextAttribute())
  105. {
  106. if(reader.Name == "id")
  107. {
  108. any.Id = reader.Value;
  109. }
  110. else if(reader.Name == "maxOccurs")
  111. {
  112. try
  113. {
  114. any.MaxOccursString = reader.Value;
  115. }
  116. catch(Exception e)
  117. {
  118. error(h,reader.Value + " is an invalid value for maxOccurs",e);
  119. }
  120. }
  121. else if(reader.Name == "minOccurs")
  122. {
  123. try
  124. {
  125. any.MinOccursString = reader.Value;
  126. }
  127. catch(Exception e)
  128. {
  129. error(h,reader.Value + " is an invalid value for minOccurs", e);
  130. }
  131. }
  132. else if(reader.Name == "namespace")
  133. {
  134. any.nameSpace = reader.Value;
  135. }
  136. else if(reader.Name == "processContents")
  137. {
  138. Exception innerex;
  139. any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader,out innerex);
  140. if(innerex != null)
  141. error(h, reader.Value + " is not a valid value for processContents",innerex);
  142. }
  143. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  144. {
  145. error(h,reader.Name + " is not a valid attribute for any",null);
  146. }
  147. else
  148. {
  149. XmlSchemaUtil.ReadUnhandledAttribute(reader,any);
  150. }
  151. }
  152. reader.MoveToElement();
  153. if(reader.IsEmptyElement)
  154. return any;
  155. // Content: (annotation?)
  156. int level = 1;
  157. while(reader.ReadNextElement())
  158. {
  159. if(reader.NodeType == XmlNodeType.EndElement)
  160. {
  161. if(reader.LocalName != xmlname)
  162. error(h,"Should not happen :2: XmlSchemaAny.Read, name="+reader.Name,null);
  163. break;
  164. }
  165. if(level <= 1 && reader.LocalName == "annotation")
  166. {
  167. level = 2; //Only one annotation
  168. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  169. if(annotation != null)
  170. any.Annotation = annotation;
  171. continue;
  172. }
  173. reader.RaiseInvalidElementError();
  174. }
  175. return any;
  176. }
  177. }
  178. }