XmlSchemaEnumerationFacet.cs 2.4 KB

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