2
0

XmlReaderSettings.cs 5.6 KB

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