XmlSchemaAnyAttribute.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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, 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. //<anyAttribute
  83. // id = ID
  84. // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  85. // processContents = (lax | skip | strict) : strict
  86. // {any attributes with non-schema namespace . . .}>
  87. // Content: (annotation?)
  88. //</anyAttribute>
  89. internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
  90. {
  91. XmlSchemaAnyAttribute any = new XmlSchemaAnyAttribute();
  92. reader.MoveToElement();
  93. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  94. {
  95. error(h,"Should not happen :1: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  96. reader.SkipToEnd();
  97. return null;
  98. }
  99. any.LineNumber = reader.LineNumber;
  100. any.LinePosition = reader.LinePosition;
  101. any.SourceUri = reader.BaseURI;
  102. while(reader.MoveToNextAttribute())
  103. {
  104. if(reader.Name == "id")
  105. {
  106. any.Id = reader.Value;
  107. }
  108. else if(reader.Name == "namespace")
  109. {
  110. any.nameSpace = reader.Value;
  111. }
  112. else if(reader.Name == "processContents")
  113. {
  114. Exception innerex;
  115. any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader,out innerex);
  116. if(innerex != null)
  117. error(h, reader.Value + " is not a valid value for processContents",innerex);
  118. }
  119. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  120. {
  121. error(h,reader.Name + " is not a valid attribute for anyAttribute",null);
  122. }
  123. else
  124. {
  125. XmlSchemaUtil.ReadUnhandledAttribute(reader,any);
  126. }
  127. }
  128. reader.MoveToElement();
  129. if(reader.IsEmptyElement)
  130. return any;
  131. // Content: (annotation?)
  132. int level = 1;
  133. while(reader.ReadNextElement())
  134. {
  135. if(reader.NodeType == XmlNodeType.EndElement)
  136. {
  137. if(reader.LocalName != xmlname)
  138. error(h,"Should not happen :2: XmlSchemaAnyAttribute.Read, name="+reader.Name,null);
  139. break;
  140. }
  141. if(level <= 1 && reader.LocalName == "annotation")
  142. {
  143. level = 2; //Only one annotation
  144. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  145. if(annotation != null)
  146. any.Annotation = annotation;
  147. continue;
  148. }
  149. reader.RaiseInvalidElementError();
  150. }
  151. return any;
  152. }
  153. }
  154. }