XmlSchemaImport.cs 2.8 KB

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