2 // XmlReaderSettings.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2004 Novell Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Xml.Schema;
36 using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
40 public sealed class XmlReaderSettings
42 private bool checkCharacters;
43 private bool closeInput;
44 private ConformanceLevel conformance;
45 private bool ignoreComments;
46 private bool ignoreProcessingInstructions;
47 private bool ignoreWhitespace;
48 private int lineNumberOffset;
49 private int linePositionOffset;
50 private bool prohibitDtd;
51 private XmlNameTable nameTable;
52 private XmlSchemaSet schemas;
53 private bool schemasNeedsInitialization;
54 private XsValidationFlags validationFlags;
55 private ValidationType validationType;
56 private XmlResolver xmlResolver;
57 #if NET_4_0 || NET_2_1
58 private DtdProcessing dtdProcessing;
60 private long maxCharactersFromEntities;
61 private long maxCharactersInDocument;
64 private bool isReadOnly;
68 public XmlReaderSettings ()
73 public event ValidationEventHandler ValidationEventHandler;
75 public XmlReaderSettings Clone ()
77 var clone = (XmlReaderSettings) MemberwiseClone ();
79 clone.isReadOnly = false;
86 checkCharacters = true;
87 closeInput = false; // ? not documented
88 conformance = ConformanceLevel.Document;
89 ignoreComments = false;
90 ignoreProcessingInstructions = false;
91 ignoreWhitespace = false;
93 linePositionOffset = 0;
96 schemasNeedsInitialization = true;
98 XsValidationFlags.ProcessIdentityConstraints |
99 XsValidationFlags.AllowXmlAttributes;
100 validationType = ValidationType.None;
101 xmlResolver = new XmlUrlResolver ();
107 public bool CheckCharacters {
108 get { return checkCharacters; }
109 set { checkCharacters = value; }
112 public bool CloseInput {
113 get { return closeInput; }
114 set { closeInput = value; }
117 public ConformanceLevel ConformanceLevel {
118 get { return conformance; }
119 set { conformance = value; }
121 #if NET_4_0 || NET_2_1
122 public DtdProcessing DtdProcessing {
123 get { return dtdProcessing; }
125 dtdProcessing = value;
126 prohibitDtd = (value == DtdProcessing.Prohibit);
130 public long MaxCharactersFromEntities {
131 get { return maxCharactersFromEntities; }
132 set { maxCharactersFromEntities = value; }
135 [MonoTODO ("not used yet")]
136 public long MaxCharactersInDocument {
137 get { return maxCharactersInDocument; }
138 set { maxCharactersInDocument = value; }
141 public bool IgnoreComments {
142 get { return ignoreComments; }
143 set { ignoreComments = value; }
146 public bool IgnoreProcessingInstructions {
147 get { return ignoreProcessingInstructions; }
148 set { ignoreProcessingInstructions = value; }
151 public bool IgnoreWhitespace {
152 get { return ignoreWhitespace; }
153 set { ignoreWhitespace = value; }
156 public int LineNumberOffset {
157 get { return lineNumberOffset; }
158 set { lineNumberOffset = value; }
161 public int LinePositionOffset {
162 get { return linePositionOffset; }
163 set { linePositionOffset = value; }
167 [ObsoleteAttribute("Use DtdProcessing property instead")]
169 public bool ProhibitDtd {
170 get { return prohibitDtd; }
171 set { prohibitDtd = value; }
174 // LAMESPEC: MSDN documentation says "An empty XmlNameTable
175 // object" for default value, but XmlNameTable cannot be
176 // instantiate. It actually returns null by default.
177 public XmlNameTable NameTable {
178 get { return nameTable; }
179 set { nameTable = value; }
182 public XmlSchemaSet Schemas {
184 if (schemasNeedsInitialization) {
185 schemas = new XmlSchemaSet ();
186 schemasNeedsInitialization = false;
192 schemasNeedsInitialization = false;
196 internal void OnValidationError (object o, ValidationEventArgs e)
198 if (ValidationEventHandler != null)
199 ValidationEventHandler (o, e);
200 else if (e.Severity == XmlSeverityType.Error)
204 internal void SetSchemas (XmlSchemaSet schemas)
206 this.schemas = schemas;
209 public XsValidationFlags ValidationFlags {
210 get { return validationFlags; }
211 set { validationFlags = value; }
214 public ValidationType ValidationType {
215 get { return validationType; }
216 set { validationType = value; }
219 public XmlResolver XmlResolver {
220 internal get { return xmlResolver; }
221 set { xmlResolver = value; }
225 internal void SetReadOnly ()
231 * FIXME: The .NET 4.5 runtime throws an exception when attempting to
232 * modify any of the properties after the XmlReader has been constructed.
234 void EnsureWritability ()
237 throw new InvalidOperationException ("XmlReaderSettings in read-only");
241 get { return isAsync; }
243 EnsureWritability ();