XmlReaderSettings.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #if !NET_2_1
  35. using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
  36. #endif
  37. namespace System.Xml
  38. {
  39. public sealed class XmlReaderSettings
  40. {
  41. private bool checkCharacters;
  42. private bool closeInput;
  43. private ConformanceLevel conformance;
  44. private bool ignoreComments;
  45. private bool ignoreProcessingInstructions;
  46. private bool ignoreWhitespace;
  47. private int lineNumberOffset;
  48. private int linePositionOffset;
  49. private bool prohibitDtd;
  50. private XmlNameTable nameTable;
  51. #if !NET_2_1
  52. private XmlSchemaSet schemas;
  53. private bool schemasNeedsInitialization;
  54. private XsValidationFlags validationFlags;
  55. private ValidationType validationType;
  56. #endif
  57. private XmlResolver xmlResolver;
  58. #if NET_2_1
  59. private DtdProcessing dtdProcessing;
  60. private Int64 maxCharactersFromEntities;
  61. #endif
  62. public XmlReaderSettings ()
  63. {
  64. Reset ();
  65. }
  66. #if !NET_2_1
  67. public event ValidationEventHandler ValidationEventHandler;
  68. #endif
  69. public XmlReaderSettings Clone ()
  70. {
  71. return (XmlReaderSettings) MemberwiseClone ();
  72. }
  73. public void Reset ()
  74. {
  75. checkCharacters = true;
  76. closeInput = false; // ? not documented
  77. conformance = ConformanceLevel.Document;
  78. ignoreComments = false;
  79. ignoreProcessingInstructions = false;
  80. ignoreWhitespace = false;
  81. lineNumberOffset = 0;
  82. linePositionOffset = 0;
  83. prohibitDtd = true;
  84. #if NET_2_1
  85. xmlResolver = new XmlXapResolver ();
  86. #else
  87. schemas = null;
  88. schemasNeedsInitialization = true;
  89. validationFlags =
  90. XsValidationFlags.ProcessIdentityConstraints |
  91. XsValidationFlags.AllowXmlAttributes;
  92. validationType = ValidationType.None;
  93. xmlResolver = new XmlUrlResolver ();
  94. #endif
  95. }
  96. public bool CheckCharacters {
  97. get { return checkCharacters; }
  98. set { checkCharacters = value; }
  99. }
  100. public bool CloseInput {
  101. get { return closeInput; }
  102. set { closeInput = value; }
  103. }
  104. public ConformanceLevel ConformanceLevel {
  105. get { return conformance; }
  106. set { conformance = value; }
  107. }
  108. #if NET_2_1
  109. public DtdProcessing DtdProcessing {
  110. get { return dtdProcessing; }
  111. set { dtdProcessing = value; }
  112. }
  113. public Int64 MaxCharactersFromEntities {
  114. get { return maxCharactersFromEntities; }
  115. set { maxCharactersFromEntities = value; }
  116. }
  117. #endif
  118. public bool IgnoreComments {
  119. get { return ignoreComments; }
  120. set { ignoreComments = value; }
  121. }
  122. public bool IgnoreProcessingInstructions {
  123. get { return ignoreProcessingInstructions; }
  124. set { ignoreProcessingInstructions = value; }
  125. }
  126. public bool IgnoreWhitespace {
  127. get { return ignoreWhitespace; }
  128. set { ignoreWhitespace = value; }
  129. }
  130. public int LineNumberOffset {
  131. get { return lineNumberOffset; }
  132. set { lineNumberOffset = value; }
  133. }
  134. public int LinePositionOffset {
  135. get { return linePositionOffset; }
  136. set { linePositionOffset = value; }
  137. }
  138. public bool ProhibitDtd {
  139. get { return prohibitDtd; }
  140. set { prohibitDtd = value; }
  141. }
  142. // LAMESPEC: MSDN documentation says "An empty XmlNameTable
  143. // object" for default value, but XmlNameTable cannot be
  144. // instantiate. It actually returns null by default.
  145. public XmlNameTable NameTable {
  146. get { return nameTable; }
  147. set { nameTable = value; }
  148. }
  149. #if !NET_2_1
  150. public XmlSchemaSet Schemas {
  151. get {
  152. if (schemasNeedsInitialization) {
  153. schemas = new XmlSchemaSet ();
  154. schemasNeedsInitialization = false;
  155. }
  156. return schemas;
  157. }
  158. set {
  159. schemas = value;
  160. schemasNeedsInitialization = false;
  161. }
  162. }
  163. internal void OnValidationError (object o, ValidationEventArgs e)
  164. {
  165. if (ValidationEventHandler != null)
  166. ValidationEventHandler (o, e);
  167. else if (e.Severity == XmlSeverityType.Error)
  168. throw e.Exception;
  169. }
  170. internal void SetSchemas (XmlSchemaSet schemas)
  171. {
  172. this.schemas = schemas;
  173. }
  174. public XsValidationFlags ValidationFlags {
  175. get { return validationFlags; }
  176. set { validationFlags = value; }
  177. }
  178. public ValidationType ValidationType {
  179. get { return validationType; }
  180. set { validationType = value; }
  181. }
  182. #endif
  183. public XmlResolver XmlResolver {
  184. internal get { return xmlResolver; }
  185. set { xmlResolver = value; }
  186. }
  187. }
  188. }
  189. #endif