XmlSchemaAnyAttribute.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.ComponentModel;
  6. using System.Xml.Serialization;
  7. namespace System.Xml.Schema
  8. {
  9. /// <summary>
  10. /// Summary description for XmlSchemaAnyAttribute.
  11. /// </summary>
  12. public class XmlSchemaAnyAttribute : XmlSchemaAnnotated
  13. {
  14. private string nameSpace;
  15. private XmlSchemaContentProcessing processing;
  16. private static string xmlname = "anyAttribute";
  17. public XmlSchemaAnyAttribute()
  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, XmlSchema schema)
  41. {
  42. // If this is already compiled this time, simply skip.
  43. if (this.IsComplied (schema.CompilationId))
  44. return 0;
  45. errorCount = 0;
  46. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  47. //define ##any=1,##other=2,##targetNamespace=4,##local=8,anyURI=16
  48. int nscount = 0;
  49. string[] nslist = XmlSchemaUtil.SplitList(Namespace);
  50. foreach(string ns in nslist)
  51. {
  52. switch(ns)
  53. {
  54. case "##any":
  55. nscount |= 1;
  56. break;
  57. case "##other":
  58. nscount |= 2;
  59. break;
  60. case "##targetNamespace":
  61. nscount |= 4;
  62. break;
  63. case "##local":
  64. nscount |= 8;
  65. break;
  66. default:
  67. if(!XmlSchemaUtil.CheckAnyUri(ns))
  68. error(h,"the namespace is not a valid anyURI");
  69. else
  70. nscount |= 16;
  71. break;
  72. }
  73. }
  74. if((nscount&1) == 1 && nscount != 1)
  75. error(h,"##any if present must be the only namespace attribute");
  76. if((nscount&2) == 2 && nscount != 2)
  77. error(h,"##other if present must be the only namespace attribute");
  78. this.CompilationId = schema.CompilationId;
  79. return errorCount;
  80. }
  81. [MonoTODO]
  82. internal int Validate(ValidationEventHandler h)
  83. {
  84. return errorCount;
  85. }
  86. //<anyAttribute
  87. // id = ID
  88. // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  89. // processContents = (lax | skip | strict) : strict
  90. // {any attributes with non-schema namespace . . .}>
  91. // Content: (annotation?)
  92. //</anyAttribute>
  93. internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
  94. {
  95. XmlSchemaAnyAttribute any = new XmlSchemaAnyAttribute();
  96. reader.MoveToElement();
  97. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  98. {
  99. error(h,"Should not happen :1: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  100. reader.SkipToEnd();
  101. return null;
  102. }
  103. any.LineNumber = reader.LineNumber;
  104. any.LinePosition = reader.LinePosition;
  105. any.SourceUri = reader.BaseURI;
  106. while(reader.MoveToNextAttribute())
  107. {
  108. if(reader.Name == "id")
  109. {
  110. any.Id = reader.Value;
  111. }
  112. else if(reader.Name == "namespace")
  113. {
  114. any.nameSpace = reader.Value;
  115. }
  116. else if(reader.Name == "processContents")
  117. {
  118. Exception innerex;
  119. any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader,out innerex);
  120. if(innerex != null)
  121. error(h, reader.Value + " is not a valid value for processContents",innerex);
  122. }
  123. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  124. {
  125. error(h,reader.Name + " is not a valid attribute for anyAttribute",null);
  126. }
  127. else
  128. {
  129. XmlSchemaUtil.ReadUnhandledAttribute(reader,any);
  130. }
  131. }
  132. reader.MoveToElement();
  133. if(reader.IsEmptyElement)
  134. return any;
  135. // Content: (annotation?)
  136. int level = 1;
  137. while(reader.ReadNextElement())
  138. {
  139. if(reader.NodeType == XmlNodeType.EndElement)
  140. {
  141. if(reader.LocalName != xmlname)
  142. error(h,"Should not happen :2: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  143. break;
  144. }
  145. if(level <= 1 && reader.LocalName == "annotation")
  146. {
  147. level = 2; //Only one annotation
  148. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  149. if(annotation != null)
  150. any.Annotation = annotation;
  151. continue;
  152. }
  153. reader.RaiseInvalidElementError();
  154. }
  155. return any;
  156. }
  157. }
  158. }