XmlSchemaInclude.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 XmlSchemaInclude.
  10. /// </summary>
  11. public class XmlSchemaInclude : XmlSchemaExternal
  12. {
  13. private XmlSchemaAnnotation annotation;
  14. private static string xmlname = "include";
  15. public XmlSchemaInclude()
  16. {
  17. }
  18. [XmlElement("annotation",Namespace=XmlSchema.Namespace)]
  19. public XmlSchemaAnnotation Annotation
  20. {
  21. get{ return annotation; }
  22. set{ annotation = value; }
  23. }
  24. //<include
  25. // id = ID
  26. // schemaLocation = anyURI
  27. // {any attributes with non-schema namespace . . .}>
  28. // Content: (annotation?)
  29. //</include>
  30. internal static XmlSchemaInclude Read(XmlSchemaReader reader, ValidationEventHandler h)
  31. {
  32. XmlSchemaInclude include = new XmlSchemaInclude();
  33. reader.MoveToElement();
  34. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  35. {
  36. error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);
  37. reader.SkipToEnd();
  38. return null;
  39. }
  40. include.LineNumber = reader.LineNumber;
  41. include.LinePosition = reader.LinePosition;
  42. include.SourceUri = reader.BaseURI;
  43. while(reader.MoveToNextAttribute())
  44. {
  45. if(reader.Name == "id")
  46. {
  47. include.Id = reader.Value;
  48. }
  49. else if(reader.Name == "schemaLocation")
  50. {
  51. include.SchemaLocation = reader.Value;
  52. }
  53. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  54. {
  55. error(h,reader.Name + " is not a valid attribute for include",null);
  56. }
  57. else
  58. {
  59. XmlSchemaUtil.ReadUnhandledAttribute(reader,include);
  60. }
  61. }
  62. reader.MoveToElement();
  63. if(reader.IsEmptyElement)
  64. return include;
  65. // Content: (annotation?)
  66. int level = 1;
  67. while(reader.ReadNextElement())
  68. {
  69. if(reader.NodeType == XmlNodeType.EndElement)
  70. {
  71. if(reader.LocalName != xmlname)
  72. error(h,"Should not happen :2: XmlSchemaInclude.Read, name="+reader.Name,null);
  73. break;
  74. }
  75. if(level <= 1 && reader.LocalName == "annotation")
  76. {
  77. level = 2; //Only one annotation
  78. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  79. if(annotation != null)
  80. include.Annotation = annotation;
  81. continue;
  82. }
  83. reader.RaiseInvalidElementError();
  84. }
  85. return include;
  86. }
  87. }
  88. }