XmlSchemaSimpleContent.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // System.Xml.Schema.XmlSchemaSimpleContent.cs
  3. //
  4. // Author:
  5. // Dwivedi, Ajay kumar [email protected]
  6. // Atsushi Enomoto [email protected]
  7. //
  8. using System;
  9. using System.Xml.Serialization;
  10. using System.Xml;
  11. namespace System.Xml.Schema
  12. {
  13. /// <summary>
  14. /// Summary description for XmlSchemaSimpleContent.
  15. /// </summary>
  16. public class XmlSchemaSimpleContent : XmlSchemaContentModel
  17. {
  18. private XmlSchemaContent content;
  19. private static string xmlname = "simpleContent";
  20. internal object actualBaseSchemaType;
  21. public XmlSchemaSimpleContent()
  22. {
  23. }
  24. [XmlElement("restriction",typeof(XmlSchemaSimpleContentRestriction),Namespace=XmlSchema.Namespace)]
  25. [XmlElement("extension",typeof(XmlSchemaSimpleContentExtension),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 and one of restriction or extention
  33. ///</remarks>
  34. [MonoTODO]
  35. internal override 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 simpleContent");
  43. }
  44. else
  45. {
  46. if(Content is XmlSchemaSimpleContentRestriction)
  47. {
  48. XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;
  49. errorCount += xscr.Compile(h, schema);
  50. }
  51. else if(Content is XmlSchemaSimpleContentExtension)
  52. {
  53. XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;
  54. errorCount += xsce.Compile(h, schema);
  55. }
  56. else
  57. error(h,"simpleContent 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 override int Validate(ValidationEventHandler h, XmlSchema schema)
  65. {
  66. if (IsValidated (schema.ValidationId))
  67. return errorCount;
  68. errorCount += this.Content.Validate (h, schema);
  69. ValidationId = schema.ValidationId;
  70. return errorCount;
  71. }
  72. //<simpleContent
  73. // id = ID
  74. // {any attributes with non-schema namespace . . .}>
  75. // Content: (annotation?, (restriction | extension))
  76. //</simpleContent>
  77. internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
  78. {
  79. XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();
  80. reader.MoveToElement();
  81. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  82. {
  83. error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  84. reader.SkipToEnd();
  85. return null;
  86. }
  87. simple.LineNumber = reader.LineNumber;
  88. simple.LinePosition = reader.LinePosition;
  89. simple.SourceUri = reader.BaseURI;
  90. while(reader.MoveToNextAttribute())
  91. {
  92. if(reader.Name == "id")
  93. {
  94. simple.Id = reader.Value;
  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 simpleContent",null);
  99. }
  100. else
  101. {
  102. XmlSchemaUtil.ReadUnhandledAttribute(reader,simple);
  103. }
  104. }
  105. reader.MoveToElement();
  106. if(reader.IsEmptyElement)
  107. return simple;
  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: XmlSchemaSimpleContent.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. simple.Annotation = annotation;
  124. continue;
  125. }
  126. if(level <=2)
  127. {
  128. if(reader.LocalName == "restriction")
  129. {
  130. level = 3;
  131. XmlSchemaSimpleContentRestriction restriction = XmlSchemaSimpleContentRestriction.Read(reader,h);
  132. if(restriction != null)
  133. simple.content = restriction;
  134. continue;
  135. }
  136. if(reader.LocalName == "extension")
  137. {
  138. level = 3;
  139. XmlSchemaSimpleContentExtension extension = XmlSchemaSimpleContentExtension.Read(reader,h);
  140. if(extension != null)
  141. simple.content = extension;
  142. continue;
  143. }
  144. }
  145. reader.RaiseInvalidElementError();
  146. }
  147. return simple;
  148. }
  149. }
  150. }