XmlSchemaComplexContent.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. using System.Xml;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaComplexContent.
  10. /// </summary>
  11. public class XmlSchemaComplexContent : XmlSchemaContentModel
  12. {
  13. private XmlSchemaContent content;
  14. private bool isMixed;
  15. private static string xmlname = "complexContent";
  16. public XmlSchemaComplexContent()
  17. {}
  18. [System.Xml.Serialization.XmlAttribute("mixed")]
  19. public bool IsMixed
  20. {
  21. get{ return isMixed; }
  22. set{ isMixed = value; }
  23. }
  24. [XmlElement("restriction",typeof(XmlSchemaComplexContentRestriction),Namespace=XmlSchema.Namespace)]
  25. [XmlElement("extension",typeof(XmlSchemaComplexContentExtension),Namespace=XmlSchema.Namespace)]
  26. public override XmlSchemaContent Content
  27. {
  28. get{ return content; }
  29. set{ content = value; }
  30. }
  31. /// <remarks>
  32. /// 1. Content must be present
  33. /// </remarks>
  34. [MonoTODO]
  35. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  36. {
  37. // If this is already compiled this time, simply skip.
  38. if (this.IsComplied (schema.CompilationId))
  39. return 0;
  40. if(Content == null)
  41. {
  42. error(h, "Content must be present in a complexContent");
  43. }
  44. else
  45. {
  46. if(Content is XmlSchemaComplexContentRestriction)
  47. {
  48. XmlSchemaComplexContentRestriction xscr = (XmlSchemaComplexContentRestriction) Content;
  49. errorCount += xscr.Compile(h, schema);
  50. }
  51. else if(Content is XmlSchemaComplexContentExtension)
  52. {
  53. XmlSchemaComplexContentExtension xsce = (XmlSchemaComplexContentExtension) Content;
  54. errorCount += xsce.Compile(h, schema);
  55. }
  56. else
  57. error(h,"complexContent can't have any value other than restriction or extention");
  58. }
  59. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  60. this.CompilationId = schema.CompilationId;
  61. return errorCount;
  62. }
  63. [MonoTODO]
  64. internal int Validate(ValidationEventHandler h)
  65. {
  66. return errorCount;
  67. }
  68. //<complexContent
  69. // id = ID
  70. // mixed = boolean
  71. // {any attributes with non-schema namespace . . .}>
  72. // Content: (annotation?, (restriction | extension))
  73. //</complexContent>
  74. internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
  75. {
  76. XmlSchemaComplexContent complex = new XmlSchemaComplexContent();
  77. reader.MoveToElement();
  78. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  79. {
  80. error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  81. reader.Skip();
  82. return null;
  83. }
  84. complex.LineNumber = reader.LineNumber;
  85. complex.LinePosition = reader.LinePosition;
  86. complex.SourceUri = reader.BaseURI;
  87. while(reader.MoveToNextAttribute())
  88. {
  89. if(reader.Name == "id")
  90. {
  91. complex.Id = reader.Value;
  92. }
  93. else if(reader.Name == "mixed")
  94. {
  95. Exception innerex;
  96. complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
  97. if(innerex != null)
  98. error(h,reader.Value + " is an invalid value for mixed",innerex);
  99. }
  100. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  101. {
  102. error(h,reader.Name + " is not a valid attribute for complexContent",null);
  103. }
  104. else
  105. {
  106. XmlSchemaUtil.ReadUnhandledAttribute(reader,complex);
  107. }
  108. }
  109. reader.MoveToElement();
  110. if(reader.IsEmptyElement)
  111. return complex;
  112. //Content: (annotation?, (restriction | extension))
  113. int level = 1;
  114. while(reader.ReadNextElement())
  115. {
  116. if(reader.NodeType == XmlNodeType.EndElement)
  117. {
  118. if(reader.LocalName != xmlname)
  119. error(h,"Should not happen :2: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  120. break;
  121. }
  122. if(level <= 1 && reader.LocalName == "annotation")
  123. {
  124. level = 2; //Only one annotation
  125. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  126. if(annotation != null)
  127. complex.Annotation = annotation;
  128. continue;
  129. }
  130. if(level <=2)
  131. {
  132. if(reader.LocalName == "restriction")
  133. {
  134. level = 3;
  135. XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader,h);
  136. if(restriction != null)
  137. complex.content = restriction;
  138. continue;
  139. }
  140. if(reader.LocalName == "extension")
  141. {
  142. level = 3;
  143. XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader,h);
  144. if(extension != null)
  145. complex.content = extension;
  146. continue;
  147. }
  148. }
  149. reader.RaiseInvalidElementError();
  150. }
  151. return complex;
  152. }
  153. }
  154. }