XmlSchemaSimpleContent.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 XmlSchemaSimpleContent.
  10. /// </summary>
  11. public class XmlSchemaSimpleContent : XmlSchemaContentModel
  12. {
  13. private XmlSchemaContent content;
  14. private static string xmlname = "simpleContent";
  15. public XmlSchemaSimpleContent()
  16. {
  17. }
  18. [XmlElement("restriction",typeof(XmlSchemaSimpleContentRestriction),Namespace="http://www.w3.org/2001/XMLSchema")]
  19. [XmlElement("extension",typeof(XmlSchemaSimpleContentExtension),Namespace="http://www.w3.org/2001/XMLSchema")]
  20. public override XmlSchemaContent Content
  21. {
  22. get{ return content; }
  23. set{ content = value; }
  24. }
  25. ///<remarks>
  26. /// 1. Content must be present and one of restriction or extention
  27. ///</remarks>
  28. [MonoTODO]
  29. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  30. {
  31. if(Content == null)
  32. {
  33. error(h, "Content must be present in a simpleContent");
  34. }
  35. else
  36. {
  37. if(Content is XmlSchemaSimpleContentRestriction)
  38. {
  39. XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;
  40. errorCount += xscr.Compile(h,info);
  41. }
  42. else if(Content is XmlSchemaSimpleContentExtension)
  43. {
  44. XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;
  45. errorCount += xsce.Compile(h,info);
  46. }
  47. else
  48. error(h,"simpleContent can't have any value other than restriction or extention");
  49. }
  50. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  51. return errorCount;
  52. }
  53. [MonoTODO]
  54. internal int Validate(ValidationEventHandler h)
  55. {
  56. return errorCount;
  57. }
  58. //<simpleContent
  59. // id = ID
  60. // {any attributes with non-schema namespace . . .}>
  61. // Content: (annotation?, (restriction | extension))
  62. //</simpleContent>
  63. internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
  64. {
  65. XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();
  66. reader.MoveToElement();
  67. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  68. {
  69. error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);
  70. reader.SkipToEnd();
  71. return null;
  72. }
  73. simple.LineNumber = reader.LineNumber;
  74. simple.LinePosition = reader.LinePosition;
  75. simple.SourceUri = reader.BaseURI;
  76. while(reader.MoveToNextAttribute())
  77. {
  78. if(reader.Name == "id")
  79. {
  80. simple.Id = reader.Value;
  81. }
  82. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  83. {
  84. error(h,reader.Name + " is not a valid attribute for simpleContent",null);
  85. }
  86. else
  87. {
  88. XmlSchemaUtil.ReadUnhandledAttribute(reader,simple);
  89. }
  90. }
  91. reader.MoveToElement();
  92. if(reader.IsEmptyElement)
  93. return simple;
  94. //Content: (annotation?, (restriction | extension))
  95. int level = 1;
  96. while(reader.ReadNextElement())
  97. {
  98. if(reader.NodeType == XmlNodeType.EndElement)
  99. {
  100. if(reader.LocalName != xmlname)
  101. error(h,"Should not happen :2: XmlSchemaSimpleContent.Read, name="+reader.Name,null);
  102. break;
  103. }
  104. if(level <= 1 && reader.LocalName == "annotation")
  105. {
  106. level = 2; //Only one annotation
  107. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  108. if(annotation != null)
  109. simple.Annotation = annotation;
  110. continue;
  111. }
  112. if(level <=2)
  113. {
  114. if(reader.LocalName == "restriction")
  115. {
  116. level = 3;
  117. XmlSchemaSimpleContentRestriction restriction = XmlSchemaSimpleContentRestriction.Read(reader,h);
  118. if(restriction != null)
  119. simple.content = restriction;
  120. continue;
  121. }
  122. if(reader.LocalName == "extension")
  123. {
  124. level = 3;
  125. XmlSchemaSimpleContentExtension extension = XmlSchemaSimpleContentExtension.Read(reader,h);
  126. if(extension != null)
  127. simple.content = extension;
  128. continue;
  129. }
  130. }
  131. reader.RaiseInvalidElementError();
  132. }
  133. return simple;
  134. }
  135. }
  136. }