XmlSchemaAnyAttribute.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // System.Xml.Schema.XmlSchemaAnyAttribute.cs
  3. //
  4. // Author:
  5. // Dwivedi, Ajay kumar [email protected]
  6. // Atsushi Enomoto [email protected]
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Specialized;
  31. using System.Xml;
  32. using System.ComponentModel;
  33. using System.Xml.Serialization;
  34. using Mono.Xml.Schema;
  35. namespace System.Xml.Schema
  36. {
  37. /// <summary>
  38. /// Summary description for XmlSchemaAnyAttribute.
  39. /// </summary>
  40. public class XmlSchemaAnyAttribute : XmlSchemaAnnotated
  41. {
  42. private string nameSpace;
  43. private XmlSchemaContentProcessing processing;
  44. const string xmlname = "anyAttribute";
  45. private XsdWildcard wildcard;
  46. public XmlSchemaAnyAttribute()
  47. {
  48. wildcard = new XsdWildcard (this);
  49. }
  50. [System.Xml.Serialization.XmlAttribute("namespace")]
  51. public string Namespace
  52. {
  53. get{ return nameSpace; }
  54. set{ nameSpace = value; }
  55. }
  56. [DefaultValue(XmlSchemaContentProcessing.None)]
  57. [System.Xml.Serialization.XmlAttribute("processContents")]
  58. public XmlSchemaContentProcessing ProcessContents
  59. {
  60. get{ return processing; }
  61. set{ processing = value; }
  62. }
  63. // Internal
  64. internal bool HasValueAny {
  65. get { return wildcard.HasValueAny; }
  66. }
  67. internal bool HasValueLocal {
  68. get { return wildcard.HasValueLocal; }
  69. }
  70. internal bool HasValueOther {
  71. get { return wildcard.HasValueOther; }
  72. }
  73. internal bool HasValueTargetNamespace {
  74. get { return wildcard.HasValueTargetNamespace; }
  75. }
  76. internal StringCollection ResolvedNamespaces {
  77. get { return wildcard.ResolvedNamespaces; }
  78. }
  79. internal XmlSchemaContentProcessing ResolvedProcessContents
  80. {
  81. get{ return wildcard.ResolvedProcessing; }
  82. }
  83. internal string TargetNamespace
  84. {
  85. get { return wildcard.TargetNamespace; }
  86. }
  87. /// <remarks>
  88. /// 1. id must be of type ID
  89. /// 2. namespace can have one of the following values:
  90. /// a) ##any or ##other
  91. /// b) list of anyURI and ##targetNamespace and ##local
  92. /// </remarks>
  93. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  94. {
  95. // If this is already compiled this time, simply skip.
  96. if (this.IsComplied (schema.CompilationId))
  97. return 0;
  98. errorCount = 0;
  99. wildcard.TargetNamespace = schema.TargetNamespace;
  100. if (wildcard.TargetNamespace == null)
  101. wildcard.TargetNamespace = "";
  102. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  103. wildcard.Compile (Namespace, h, schema);
  104. if (processing == XmlSchemaContentProcessing.None)
  105. wildcard.ResolvedProcessing = XmlSchemaContentProcessing.Strict;
  106. else
  107. wildcard.ResolvedProcessing = processing;
  108. this.CompilationId = schema.CompilationId;
  109. return errorCount;
  110. }
  111. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  112. {
  113. return errorCount;
  114. }
  115. // 3.10.6 Wildcard Subset
  116. internal void ValidateWildcardSubset (XmlSchemaAnyAttribute other,
  117. ValidationEventHandler h, XmlSchema schema)
  118. {
  119. wildcard.ValidateWildcardSubset (other.wildcard, h, schema);
  120. }
  121. internal bool ValidateWildcardAllowsNamespaceName (string ns, XmlSchema schema)
  122. {
  123. return wildcard.ValidateWildcardAllowsNamespaceName (ns, null, schema, false);
  124. }
  125. //<anyAttribute
  126. // id = ID
  127. // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  128. // processContents = (lax | skip | strict) : strict
  129. // {any attributes with non-schema namespace . . .}>
  130. // Content: (annotation?)
  131. //</anyAttribute>
  132. internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
  133. {
  134. XmlSchemaAnyAttribute any = new XmlSchemaAnyAttribute();
  135. reader.MoveToElement();
  136. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  137. {
  138. error(h,"Should not happen :1: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  139. reader.SkipToEnd();
  140. return null;
  141. }
  142. any.LineNumber = reader.LineNumber;
  143. any.LinePosition = reader.LinePosition;
  144. any.SourceUri = reader.BaseURI;
  145. while(reader.MoveToNextAttribute())
  146. {
  147. if(reader.Name == "id")
  148. {
  149. any.Id = reader.Value;
  150. }
  151. else if(reader.Name == "namespace")
  152. {
  153. any.nameSpace = reader.Value;
  154. }
  155. else if(reader.Name == "processContents")
  156. {
  157. Exception innerex;
  158. any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader,out innerex);
  159. if(innerex != null)
  160. error(h, reader.Value + " is not a valid value for processContents",innerex);
  161. }
  162. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  163. {
  164. error(h,reader.Name + " is not a valid attribute for anyAttribute",null);
  165. }
  166. else
  167. {
  168. XmlSchemaUtil.ReadUnhandledAttribute(reader,any);
  169. }
  170. }
  171. reader.MoveToElement();
  172. if(reader.IsEmptyElement)
  173. return any;
  174. // Content: (annotation?)
  175. int level = 1;
  176. while(reader.ReadNextElement())
  177. {
  178. if(reader.NodeType == XmlNodeType.EndElement)
  179. {
  180. if(reader.LocalName != xmlname)
  181. error(h,"Should not happen :2: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  182. break;
  183. }
  184. if(level <= 1 && reader.LocalName == "annotation")
  185. {
  186. level = 2; //Only one annotation
  187. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  188. if(annotation != null)
  189. any.Annotation = annotation;
  190. continue;
  191. }
  192. reader.RaiseInvalidElementError();
  193. }
  194. return any;
  195. }
  196. }
  197. }