XmlSchemaInclude.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.Serialization;
  25. using System.Xml;
  26. namespace System.Xml.Schema
  27. {
  28. /// <summary>
  29. /// Summary description for XmlSchemaInclude.
  30. /// </summary>
  31. public class XmlSchemaInclude : XmlSchemaExternal
  32. {
  33. private XmlSchemaAnnotation annotation;
  34. const string xmlname = "include";
  35. public XmlSchemaInclude()
  36. {
  37. }
  38. [XmlElement("annotation", Type=typeof (XmlSchemaAnnotation))]
  39. public XmlSchemaAnnotation Annotation
  40. {
  41. get{ return annotation; }
  42. set{ annotation = value; }
  43. }
  44. //<include
  45. // id = ID
  46. // schemaLocation = anyURI
  47. // {any attributes with non-schema namespace . . .}>
  48. // Content: (annotation?)
  49. //</include>
  50. internal static XmlSchemaInclude Read(XmlSchemaReader reader, ValidationEventHandler h)
  51. {
  52. XmlSchemaInclude include = new XmlSchemaInclude();
  53. reader.MoveToElement();
  54. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  55. {
  56. error(h,"Should not happen :1: XmlSchemaInclude.Read, name="+reader.Name,null);
  57. reader.SkipToEnd();
  58. return null;
  59. }
  60. include.LineNumber = reader.LineNumber;
  61. include.LinePosition = reader.LinePosition;
  62. include.SourceUri = reader.BaseURI;
  63. while(reader.MoveToNextAttribute())
  64. {
  65. if(reader.Name == "id")
  66. {
  67. include.Id = reader.Value;
  68. }
  69. else if(reader.Name == "schemaLocation")
  70. {
  71. include.SchemaLocation = reader.Value;
  72. }
  73. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  74. {
  75. error(h,reader.Name + " is not a valid attribute for include",null);
  76. }
  77. else
  78. {
  79. XmlSchemaUtil.ReadUnhandledAttribute(reader,include);
  80. }
  81. }
  82. reader.MoveToElement();
  83. if(reader.IsEmptyElement)
  84. return include;
  85. // Content: (annotation?)
  86. int level = 1;
  87. while(reader.ReadNextElement())
  88. {
  89. if(reader.NodeType == XmlNodeType.EndElement)
  90. {
  91. if(reader.LocalName != xmlname)
  92. error(h,"Should not happen :2: XmlSchemaInclude.Read, name="+reader.Name,null);
  93. break;
  94. }
  95. if(level <= 1 && reader.LocalName == "annotation")
  96. {
  97. level = 2; //Only one annotation
  98. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  99. if(annotation != null)
  100. include.Annotation = annotation;
  101. continue;
  102. }
  103. reader.RaiseInvalidElementError();
  104. }
  105. return include;
  106. }
  107. }
  108. }