XmlReaderSettings.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // XmlReaderSettings.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2004 Novell Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.IO;
  32. using System.Net;
  33. using System.Xml.Schema;
  34. using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
  35. namespace System.Xml
  36. {
  37. public class XmlReaderSettings
  38. {
  39. private bool checkCharacters;
  40. private bool closeInput;
  41. private ConformanceLevel conformance;
  42. private bool ignoreComments;
  43. private bool ignoreProcessingInstructions;
  44. private bool ignoreWhitespace;
  45. private int lineNumberOffset;
  46. private int linePositionOffset;
  47. private bool prohibitDtd;
  48. private XmlNameTable nameTable;
  49. private XmlSchemaSet schemas;
  50. private XsValidationFlags validationFlags;
  51. private ValidationType validationType;
  52. private XmlResolver xmlResolver;
  53. public XmlReaderSettings ()
  54. {
  55. Reset ();
  56. }
  57. private XmlReaderSettings (XmlReaderSettings org)
  58. {
  59. checkCharacters = org.checkCharacters;
  60. closeInput = org.closeInput;
  61. conformance = org.conformance;
  62. ignoreComments = org.ignoreComments;
  63. ignoreProcessingInstructions =
  64. org.ignoreProcessingInstructions;
  65. ignoreWhitespace = org.ignoreWhitespace;
  66. lineNumberOffset = org.lineNumberOffset;
  67. linePositionOffset = org.linePositionOffset;
  68. prohibitDtd = org.prohibitDtd;
  69. schemas = org.schemas;
  70. validationFlags = org.validationFlags;
  71. validationType = org.validationType;
  72. nameTable = org.nameTable;
  73. xmlResolver = org.xmlResolver;
  74. }
  75. public event ValidationEventHandler ValidationEventHandler;
  76. public XmlReaderSettings Clone ()
  77. {
  78. return new XmlReaderSettings (this);
  79. }
  80. public void Reset ()
  81. {
  82. checkCharacters = true;
  83. closeInput = false; // ? not documented
  84. conformance = ConformanceLevel.Document;
  85. ignoreComments = false;
  86. ignoreProcessingInstructions = false;
  87. ignoreWhitespace = false;
  88. lineNumberOffset = 0;
  89. linePositionOffset = 0;
  90. prohibitDtd = false; // ? not documented
  91. schemas = new XmlSchemaSet ();
  92. validationFlags =
  93. XsValidationFlags.IgnoreValidationWarnings
  94. | XsValidationFlags.IgnoreSchemaLocation
  95. | XsValidationFlags.IgnoreInlineSchema;
  96. validationType = ValidationType.None;
  97. xmlResolver = new XmlUrlResolver ();
  98. }
  99. public bool CheckCharacters {
  100. get { return checkCharacters; }
  101. set { checkCharacters = value; }
  102. }
  103. public bool CloseInput {
  104. get { return closeInput; }
  105. set { closeInput = value; }
  106. }
  107. public ConformanceLevel ConformanceLevel {
  108. get { return conformance; }
  109. set { conformance = value; }
  110. }
  111. public bool IgnoreComments {
  112. get { return ignoreComments; }
  113. set { ignoreComments = value; }
  114. }
  115. public bool IgnoreProcessingInstructions {
  116. get { return ignoreProcessingInstructions; }
  117. set { ignoreProcessingInstructions = value; }
  118. }
  119. public bool IgnoreWhitespace {
  120. get { return ignoreWhitespace; }
  121. set { ignoreWhitespace = value; }
  122. }
  123. public int LineNumberOffset {
  124. get { return lineNumberOffset; }
  125. set { lineNumberOffset = value; }
  126. }
  127. public int LinePositionOffset {
  128. get { return linePositionOffset; }
  129. set { linePositionOffset = value; }
  130. }
  131. public bool ProhibitDtd {
  132. get { return prohibitDtd; }
  133. set { prohibitDtd = value; }
  134. }
  135. // LAMESPEC: MSDN documentation says "An empty XmlNameTable
  136. // object" for default value, but XmlNameTable cannot be
  137. // instantiate. It actually returns null by default.
  138. public XmlNameTable NameTable {
  139. get { return nameTable; }
  140. set { nameTable = value; }
  141. }
  142. // LAMESPEC: Apparently, this property should not have a setter.
  143. public XmlSchemaSet Schemas {
  144. get { return schemas; }
  145. set {
  146. throw new XmlException ("XmlReaderSettings.Schemas is read-only and cannot be set.");
  147. }
  148. }
  149. internal void SetSchemas (XmlSchemaSet schemas)
  150. {
  151. this.schemas = schemas;
  152. }
  153. public XsValidationFlags ValidationFlags {
  154. get { return validationFlags; }
  155. set { validationFlags = value; }
  156. }
  157. public ValidationType ValidationType {
  158. get { return validationType; }
  159. set { validationType = value; }
  160. }
  161. public XmlResolver XmlResolver {
  162. internal get { return xmlResolver; }
  163. set { xmlResolver = value; }
  164. }
  165. }
  166. }
  167. #endif