XmlSchemaComplexContent.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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="http://www.w3.org/2001/XMLSchema")]
  25. [XmlElement("extension",typeof(XmlSchemaComplexContentExtension),Namespace="http://www.w3.org/2001/XMLSchema")]
  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, XmlSchemaInfo info)
  36. {
  37. if(Content == null)
  38. {
  39. error(h, "Content must be present in a complexContent");
  40. }
  41. else
  42. {
  43. if(Content is XmlSchemaComplexContentRestriction)
  44. {
  45. XmlSchemaComplexContentRestriction xscr = (XmlSchemaComplexContentRestriction) Content;
  46. errorCount += xscr.Compile(h,info);
  47. }
  48. else if(Content is XmlSchemaComplexContentExtension)
  49. {
  50. XmlSchemaComplexContentExtension xsce = (XmlSchemaComplexContentExtension) Content;
  51. errorCount += xsce.Compile(h,info);
  52. }
  53. else
  54. error(h,"complexContent can't have any value other than restriction or extention");
  55. }
  56. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  57. return errorCount;
  58. }
  59. [MonoTODO]
  60. internal int Validate(ValidationEventHandler h)
  61. {
  62. return errorCount;
  63. }
  64. //<complexContent
  65. // id = ID
  66. // mixed = boolean
  67. // {any attributes with non-schema namespace . . .}>
  68. // Content: (annotation?, (restriction | extension))
  69. //</complexContent>
  70. internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
  71. {
  72. XmlSchemaComplexContent complex = new XmlSchemaComplexContent();
  73. reader.MoveToElement();
  74. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  75. {
  76. error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  77. reader.Skip();
  78. return null;
  79. }
  80. complex.LineNumber = reader.LineNumber;
  81. complex.LinePosition = reader.LinePosition;
  82. complex.SourceUri = reader.BaseURI;
  83. while(reader.MoveToNextAttribute())
  84. {
  85. if(reader.Name == "id")
  86. {
  87. complex.Id = reader.Value;
  88. }
  89. else if(reader.Name == "mixed")
  90. {
  91. Exception innerex;
  92. complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
  93. if(innerex != null)
  94. error(h,reader.Value + " is an invalid value for mixed",innerex);
  95. }
  96. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  97. {
  98. error(h,reader.Name + " is not a valid attribute for complexContent",null);
  99. }
  100. else
  101. {
  102. XmlSchemaUtil.ReadUnhandledAttribute(reader,complex);
  103. }
  104. }
  105. reader.MoveToElement();
  106. if(reader.IsEmptyElement)
  107. return complex;
  108. //Content: (annotation?, (restriction | extension))
  109. int level = 1;
  110. while(reader.ReadNextElement())
  111. {
  112. if(reader.NodeType == XmlNodeType.EndElement)
  113. {
  114. if(reader.LocalName != xmlname)
  115. error(h,"Should not happen :2: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  116. break;
  117. }
  118. if(level <= 1 && reader.LocalName == "annotation")
  119. {
  120. level = 2; //Only one annotation
  121. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  122. if(annotation != null)
  123. complex.Annotation = annotation;
  124. continue;
  125. }
  126. if(level <=2)
  127. {
  128. if(reader.LocalName == "restriction")
  129. {
  130. level = 3;
  131. XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader,h);
  132. if(restriction != null)
  133. complex.content = restriction;
  134. continue;
  135. }
  136. if(reader.LocalName == "extension")
  137. {
  138. level = 3;
  139. XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader,h);
  140. if(extension != null)
  141. complex.content = extension;
  142. continue;
  143. }
  144. }
  145. reader.RaiseInvalidElementError();
  146. }
  147. return complex;
  148. }
  149. }
  150. }