2
0

XmlSchemaAnyAttribute.cs 5.5 KB

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