XmlSchemaEnumerationFacet.cs 3.5 KB

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