XmlSchemaMaxLengthFacet.cs 2.6 KB

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