XmlReaderSettings.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. [Obsolete ("Use ValidationFlags")]
  116. public bool IgnoreIdentityConstraints {
  117. get { return (ValidationFlags & XsValidationFlags.IgnoreIdentityConstraints) != 0; }
  118. set {
  119. if (value)
  120. ValidationFlags |= XsValidationFlags.IgnoreIdentityConstraints;
  121. else
  122. ValidationFlags &= ~XsValidationFlags.IgnoreIdentityConstraints;
  123. }
  124. }
  125. [Obsolete ("Use ValidationFlags")]
  126. public bool IgnoreInlineSchema {
  127. get { return (ValidationFlags & XsValidationFlags.IgnoreInlineSchema) != 0; }
  128. set {
  129. if (value)
  130. ValidationFlags |= XsValidationFlags.IgnoreInlineSchema;
  131. else
  132. ValidationFlags &= ~XsValidationFlags.IgnoreInlineSchema;
  133. }
  134. }
  135. [Obsolete ("Use ValidationFlags")]
  136. public bool IgnoreSchemaLocation {
  137. get { return (ValidationFlags & XsValidationFlags.IgnoreSchemaLocation) != 0; }
  138. set {
  139. if (value)
  140. ValidationFlags |= XsValidationFlags.IgnoreSchemaLocation;
  141. else
  142. ValidationFlags &= ~XsValidationFlags.IgnoreSchemaLocation;
  143. }
  144. }
  145. [Obsolete ("Use ValidationFlags")]
  146. public bool IgnoreValidationWarnings {
  147. get { return (ValidationFlags & XsValidationFlags.IgnoreValidationWarnings) != 0; }
  148. set {
  149. if (value)
  150. ValidationFlags |= XsValidationFlags.IgnoreValidationWarnings;
  151. else
  152. ValidationFlags &= ~XsValidationFlags.IgnoreValidationWarnings;
  153. }
  154. }
  155. public bool IgnoreProcessingInstructions {
  156. get { return ignoreProcessingInstructions; }
  157. set { ignoreProcessingInstructions = value; }
  158. }
  159. public bool IgnoreWhitespace {
  160. get { return ignoreWhitespace; }
  161. set { ignoreWhitespace = value; }
  162. }
  163. public int LineNumberOffset {
  164. get { return lineNumberOffset; }
  165. set { lineNumberOffset = value; }
  166. }
  167. public int LinePositionOffset {
  168. get { return linePositionOffset; }
  169. set { linePositionOffset = value; }
  170. }
  171. public bool ProhibitDtd {
  172. get { return prohibitDtd; }
  173. set { prohibitDtd = value; }
  174. }
  175. // LAMESPEC: MSDN documentation says "An empty XmlNameTable
  176. // object" for default value, but XmlNameTable cannot be
  177. // instantiate. It actually returns null by default.
  178. public XmlNameTable NameTable {
  179. get { return nameTable; }
  180. set { nameTable = value; }
  181. }
  182. // LAMESPEC: Apparently, this property should not have a setter.
  183. public XmlSchemaSet Schemas {
  184. get { return schemas; }
  185. set {
  186. throw new XmlException ("XmlReaderSettings.Schemas is read-only and cannot be set.");
  187. }
  188. }
  189. internal void SetSchemas (XmlSchemaSet schemas)
  190. {
  191. this.schemas = schemas;
  192. }
  193. public XsValidationFlags ValidationFlags {
  194. get { return validationFlags; }
  195. set { validationFlags = value; }
  196. }
  197. public ValidationType ValidationType {
  198. get { return validationType; }
  199. set { validationType = value; }
  200. }
  201. public XmlResolver XmlResolver {
  202. internal get { return xmlResolver; }
  203. set { xmlResolver = value; }
  204. }
  205. }
  206. }
  207. #endif