XmlSchemaRedefine.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 XmlSchemaRedefine.
  30. /// </summary>
  31. public class XmlSchemaRedefine : XmlSchemaExternal
  32. {
  33. private XmlSchemaObjectTable attributeGroups;
  34. private XmlSchemaObjectTable groups;
  35. private XmlSchemaObjectCollection items;
  36. private XmlSchemaObjectTable schemaTypes;
  37. const string xmlname = "redefine";
  38. public XmlSchemaRedefine()
  39. {
  40. attributeGroups = new XmlSchemaObjectTable();
  41. groups = new XmlSchemaObjectTable();
  42. items = new XmlSchemaObjectCollection(this);
  43. schemaTypes = new XmlSchemaObjectTable();
  44. }
  45. [XmlElement("annotation",typeof(XmlSchemaAnnotation),Namespace=XmlSchema.Namespace)]
  46. [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace=XmlSchema.Namespace)]
  47. [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace=XmlSchema.Namespace)]
  48. [XmlElement("group",typeof(XmlSchemaGroup),Namespace=XmlSchema.Namespace)]
  49. //NOTE: AttributeGroup and not AttributeGroupRef
  50. [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroup),Namespace=XmlSchema.Namespace)]
  51. public XmlSchemaObjectCollection Items
  52. {
  53. get{ return items; }
  54. }
  55. [XmlIgnore]
  56. public XmlSchemaObjectTable AttributeGroups
  57. {
  58. get{ return attributeGroups; }
  59. }
  60. [XmlIgnore]
  61. public XmlSchemaObjectTable SchemaTypes
  62. {
  63. get{ return schemaTypes; }
  64. }
  65. [XmlIgnore]
  66. public XmlSchemaObjectTable Groups
  67. {
  68. get{ return groups; }
  69. }
  70. //<redefine
  71. // id = ID
  72. // schemaLocation = anyURI
  73. // {any attributes with non-schema namespace . . .}>
  74. // Content: (annotation | (simpleType | complexType | group | attributeGroup))*
  75. //</redefine>
  76. internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
  77. {
  78. XmlSchemaRedefine redefine = new XmlSchemaRedefine();
  79. reader.MoveToElement();
  80. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  81. {
  82. error(h,"Should not happen :1: XmlSchemaRedefine.Read, name="+reader.Name,null);
  83. reader.Skip();
  84. return null;
  85. }
  86. redefine.LineNumber = reader.LineNumber;
  87. redefine.LinePosition = reader.LinePosition;
  88. redefine.SourceUri = reader.BaseURI;
  89. while(reader.MoveToNextAttribute())
  90. {
  91. if(reader.Name == "id")
  92. {
  93. redefine.Id = reader.Value;
  94. }
  95. else if(reader.Name == "schemaLocation")
  96. {
  97. redefine.SchemaLocation = reader.Value;
  98. }
  99. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  100. {
  101. error(h,reader.Name + " is not a valid attribute for redefine",null);
  102. }
  103. else
  104. {
  105. XmlSchemaUtil.ReadUnhandledAttribute(reader,redefine);
  106. }
  107. }
  108. reader.MoveToElement();
  109. if(reader.IsEmptyElement)
  110. return redefine;
  111. //(annotation | (simpleType | complexType | group | attributeGroup))*
  112. while(reader.ReadNextElement())
  113. {
  114. if(reader.NodeType == XmlNodeType.EndElement)
  115. {
  116. if(reader.LocalName != xmlname)
  117. error(h,"Should not happen :2: XmlSchemaRedefine.Read, name="+reader.Name,null);
  118. break;
  119. }
  120. if(reader.LocalName == "annotation")
  121. {
  122. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  123. if(annotation != null)
  124. redefine.items.Add(annotation);
  125. continue;
  126. }
  127. if(reader.LocalName == "simpleType")
  128. {
  129. XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader,h);
  130. if(simpleType != null)
  131. redefine.items.Add(simpleType);
  132. continue;
  133. }
  134. if(reader.LocalName == "complexType")
  135. {
  136. XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader,h);
  137. if(complexType != null)
  138. redefine.items.Add(complexType);
  139. continue;
  140. }
  141. if(reader.LocalName == "group")
  142. {
  143. XmlSchemaGroup group = XmlSchemaGroup.Read(reader,h);
  144. if(group != null)
  145. redefine.items.Add(group);
  146. continue;
  147. }
  148. if(reader.LocalName == "attributeGroup")
  149. {
  150. XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader,h);
  151. if(attributeGroup != null)
  152. redefine.items.Add(attributeGroup);
  153. continue;
  154. }
  155. reader.RaiseInvalidElementError();
  156. }
  157. return redefine;
  158. }
  159. }
  160. }