XmlReaderSettings.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 sealed 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 bool schemasNeedsInitialization;
  51. private XsValidationFlags validationFlags;
  52. private ValidationType validationType;
  53. private XmlResolver xmlResolver;
  54. public XmlReaderSettings ()
  55. {
  56. Reset ();
  57. }
  58. private XmlReaderSettings (XmlReaderSettings org)
  59. {
  60. checkCharacters = org.checkCharacters;
  61. closeInput = org.closeInput;
  62. conformance = org.conformance;
  63. ignoreComments = org.ignoreComments;
  64. ignoreProcessingInstructions =
  65. org.ignoreProcessingInstructions;
  66. ignoreWhitespace = org.ignoreWhitespace;
  67. lineNumberOffset = org.lineNumberOffset;
  68. linePositionOffset = org.linePositionOffset;
  69. prohibitDtd = org.prohibitDtd;
  70. schemas = org.schemas;
  71. validationFlags = org.validationFlags;
  72. validationType = org.validationType;
  73. nameTable = org.nameTable;
  74. xmlResolver = org.xmlResolver;
  75. }
  76. public event ValidationEventHandler ValidationEventHandler;
  77. public XmlReaderSettings Clone ()
  78. {
  79. return new XmlReaderSettings (this);
  80. }
  81. public void Reset ()
  82. {
  83. checkCharacters = true;
  84. closeInput = false; // ? not documented
  85. conformance = ConformanceLevel.Document;
  86. ignoreComments = false;
  87. ignoreProcessingInstructions = false;
  88. ignoreWhitespace = false;
  89. lineNumberOffset = 0;
  90. linePositionOffset = 0;
  91. prohibitDtd = true;
  92. schemas = null;
  93. schemasNeedsInitialization = true;
  94. validationFlags =
  95. XsValidationFlags.ProcessIdentityConstraints |
  96. XsValidationFlags.AllowXmlAttributes;
  97. validationType = ValidationType.None;
  98. xmlResolver = new XmlUrlResolver ();
  99. }
  100. public bool CheckCharacters {
  101. get { return checkCharacters; }
  102. set { checkCharacters = value; }
  103. }
  104. public bool CloseInput {
  105. get { return closeInput; }
  106. set { closeInput = value; }
  107. }
  108. public ConformanceLevel ConformanceLevel {
  109. get { return conformance; }
  110. set { conformance = value; }
  111. }
  112. public bool IgnoreComments {
  113. get { return ignoreComments; }
  114. set { ignoreComments = value; }
  115. }
  116. public bool IgnoreProcessingInstructions {
  117. get { return ignoreProcessingInstructions; }
  118. set { ignoreProcessingInstructions = value; }
  119. }
  120. public bool IgnoreWhitespace {
  121. get { return ignoreWhitespace; }
  122. set { ignoreWhitespace = value; }
  123. }
  124. public int LineNumberOffset {
  125. get { return lineNumberOffset; }
  126. set { lineNumberOffset = value; }
  127. }
  128. public int LinePositionOffset {
  129. get { return linePositionOffset; }
  130. set { linePositionOffset = value; }
  131. }
  132. public bool ProhibitDtd {
  133. get { return prohibitDtd; }
  134. set { prohibitDtd = value; }
  135. }
  136. // LAMESPEC: MSDN documentation says "An empty XmlNameTable
  137. // object" for default value, but XmlNameTable cannot be
  138. // instantiate. It actually returns null by default.
  139. public XmlNameTable NameTable {
  140. get { return nameTable; }
  141. set { nameTable = value; }
  142. }
  143. public XmlSchemaSet Schemas {
  144. get {
  145. if (schemasNeedsInitialization) {
  146. schemas = new XmlSchemaSet ();
  147. schemasNeedsInitialization = false;
  148. }
  149. return schemas;
  150. }
  151. set {
  152. schemas = value;
  153. schemasNeedsInitialization = false;
  154. }
  155. }
  156. internal void SetSchemas (XmlSchemaSet schemas)
  157. {
  158. this.schemas = schemas;
  159. }
  160. public XsValidationFlags ValidationFlags {
  161. get { return validationFlags; }
  162. set { validationFlags = value; }
  163. }
  164. public ValidationType ValidationType {
  165. get { return validationType; }
  166. set { validationType = value; }
  167. }
  168. public XmlResolver XmlResolver {
  169. internal get { return xmlResolver; }
  170. set { xmlResolver = value; }
  171. }
  172. }
  173. }
  174. #endif