XmlSchemaTotalDigitsFacet.cs 3.7 KB

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