XmlSchemaMaxLengthFacet.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 XmlSchemaMaxLengthFacet.
  9. /// </summary>
  10. public class XmlSchemaMaxLengthFacet : XmlSchemaNumericFacet
  11. {
  12. const string xmlname = "maxLength";
  13. public XmlSchemaMaxLengthFacet()
  14. {
  15. }
  16. internal override Facet ThisFacet {
  17. get { return Facet.maxLength;}
  18. }
  19. //<maxLength
  20. // fixed = boolean : false
  21. // id = ID
  22. // value = nonNegativeInteger
  23. // {any attributes with non-schema namespace . . .}>
  24. // Content: (annotation?)
  25. //</maxLength>
  26. internal static XmlSchemaMaxLengthFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
  27. {
  28. XmlSchemaMaxLengthFacet length = new XmlSchemaMaxLengthFacet();
  29. reader.MoveToElement();
  30. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  31. {
  32. error(h,"Should not happen :1: XmlSchemaMaxLengthFacet.Read, name="+reader.Name,null);
  33. reader.Skip();
  34. return null;
  35. }
  36. length.LineNumber = reader.LineNumber;
  37. length.LinePosition = reader.LinePosition;
  38. length.SourceUri = reader.BaseURI;
  39. while(reader.MoveToNextAttribute())
  40. {
  41. if(reader.Name == "id")
  42. {
  43. length.Id = reader.Value;
  44. }
  45. else if(reader.Name == "fixed")
  46. {
  47. Exception innerex;
  48. length.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
  49. if(innerex != null)
  50. error(h, reader.Value + " is not a valid value for fixed attribute",innerex);
  51. }
  52. else if(reader.Name == "value")
  53. {
  54. length.Value = reader.Value;
  55. }
  56. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  57. {
  58. error(h,reader.Name + " is not a valid attribute for group",null);
  59. }
  60. else
  61. {
  62. XmlSchemaUtil.ReadUnhandledAttribute(reader,length);
  63. }
  64. }
  65. reader.MoveToElement();
  66. if(reader.IsEmptyElement)
  67. return length;
  68. // Content: (annotation?)
  69. int level = 1;
  70. while(reader.ReadNextElement())
  71. {
  72. if(reader.NodeType == XmlNodeType.EndElement)
  73. {
  74. if(reader.LocalName != xmlname)
  75. error(h,"Should not happen :2: XmlSchemaMaxLengthFacet.Read, name="+reader.Name,null);
  76. break;
  77. }
  78. if(level <= 1 && reader.LocalName == "annotation")
  79. {
  80. level = 2; //Only one annotation
  81. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  82. if(annotation != null)
  83. length.Annotation = annotation;
  84. continue;
  85. }
  86. reader.RaiseInvalidElementError();
  87. }
  88. return length;
  89. }
  90. }
  91. }