XmlSchemaImport.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Xml;
  25. using System.Xml.Serialization;
  26. namespace System.Xml.Schema
  27. {
  28. /// <summary>
  29. /// Summary description for XmlSchemaImport.
  30. /// </summary>
  31. public class XmlSchemaImport : XmlSchemaExternal
  32. {
  33. private XmlSchemaAnnotation annotation;
  34. private string nameSpace;
  35. const string xmlname = "import";
  36. public XmlSchemaImport()
  37. {
  38. }
  39. [System.Xml.Serialization.XmlAttribute("namespace")]
  40. public string Namespace
  41. {
  42. get{ return nameSpace; }
  43. set{ nameSpace = value; }
  44. }
  45. [XmlElement("annotation",Namespace=XmlSchema.Namespace)]
  46. public XmlSchemaAnnotation Annotation
  47. {
  48. get{ return annotation; }
  49. set{ annotation = value; }
  50. }
  51. //<import
  52. // id = ID
  53. // namespace = anyURI
  54. // schemaLocation = anyURI
  55. // {any attributes with non-schema namespace . . .}>
  56. // Content: (annotation?)
  57. //</import>
  58. internal static XmlSchemaImport Read(XmlSchemaReader reader, ValidationEventHandler h)
  59. {
  60. XmlSchemaImport import = new XmlSchemaImport();
  61. reader.MoveToElement();
  62. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != "import")
  63. {
  64. error(h,"Should not happen :1: XmlSchemaImport.Read, name="+reader.Name,null);
  65. reader.SkipToEnd();
  66. return null;
  67. }
  68. import.LineNumber = reader.LineNumber;
  69. import.LinePosition = reader.LinePosition;
  70. import.SourceUri = reader.BaseURI;
  71. while(reader.MoveToNextAttribute())
  72. {
  73. if(reader.Name == "id")
  74. {
  75. import.Id = reader.Value;
  76. }
  77. else if(reader.Name == "namespace")
  78. {
  79. import.nameSpace = reader.Value;
  80. }
  81. else if(reader.Name == "schemaLocation")
  82. {
  83. import.SchemaLocation = reader.Value;
  84. }
  85. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  86. {
  87. error(h,reader.Name + " is not a valid attribute for import",null);
  88. }
  89. else
  90. {
  91. XmlSchemaUtil.ReadUnhandledAttribute(reader,import);
  92. }
  93. }
  94. reader.MoveToElement();
  95. if(reader.IsEmptyElement)
  96. return import;
  97. // Content: (annotation?)
  98. int level = 1;
  99. while(reader.ReadNextElement())
  100. {
  101. if(reader.NodeType == XmlNodeType.EndElement)
  102. {
  103. if(reader.LocalName != xmlname)
  104. error(h,"Should not happen :2: XmlSchemaImport.Read, name="+reader.Name,null);
  105. break;
  106. }
  107. if(level <= 1 && reader.LocalName == "annotation")
  108. {
  109. level = 2; //Only one annotation
  110. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  111. if(annotation != null)
  112. import.Annotation = annotation;
  113. continue;
  114. }
  115. reader.RaiseInvalidElementError();
  116. }
  117. return import;
  118. }
  119. }
  120. }