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;
37 using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
42 public sealed class XmlReaderSettings
44 private bool checkCharacters;
45 private bool closeInput;
46 private ConformanceLevel conformance;
47 private bool ignoreComments;
48 private bool ignoreProcessingInstructions;
49 private bool ignoreWhitespace;
50 private int lineNumberOffset;
51 private int linePositionOffset;
52 private bool prohibitDtd;
53 private XmlNameTable nameTable;
55 private XmlSchemaSet schemas;
56 private bool schemasNeedsInitialization;
57 private XsValidationFlags validationFlags;
58 private ValidationType validationType;
60 private XmlResolver xmlResolver;
61 #if NET_4_0 || NET_2_1
62 private DtdProcessing dtdProcessing;
64 private long maxCharactersFromEntities;
65 private long maxCharactersInDocument;
68 private bool isReadOnly;
72 public XmlReaderSettings ()
78 public event ValidationEventHandler ValidationEventHandler;
81 public XmlReaderSettings Clone ()
83 var clone = (XmlReaderSettings) MemberwiseClone ();
85 clone.isReadOnly = false;
92 checkCharacters = true;
93 closeInput = false; // ? not documented
94 conformance = ConformanceLevel.Document;
95 ignoreComments = false;
96 ignoreProcessingInstructions = false;
97 ignoreWhitespace = false;
99 linePositionOffset = 0;
102 xmlResolver = new XmlXapResolver ();
105 schemasNeedsInitialization = true;
107 XsValidationFlags.ProcessIdentityConstraints |
108 XsValidationFlags.AllowXmlAttributes;
109 validationType = ValidationType.None;
110 xmlResolver = new XmlUrlResolver ();
117 public bool CheckCharacters {
118 get { return checkCharacters; }
119 set { checkCharacters = value; }
122 public bool CloseInput {
123 get { return closeInput; }
124 set { closeInput = value; }
127 public ConformanceLevel ConformanceLevel {
128 get { return conformance; }
129 set { conformance = value; }
131 #if NET_4_0 || NET_2_1
132 public DtdProcessing DtdProcessing {
133 get { return dtdProcessing; }
135 dtdProcessing = value;
136 prohibitDtd = (value == DtdProcessing.Prohibit);
140 public long MaxCharactersFromEntities {
141 get { return maxCharactersFromEntities; }
142 set { maxCharactersFromEntities = value; }
145 [MonoTODO ("not used yet")]
146 public long MaxCharactersInDocument {
147 get { return maxCharactersInDocument; }
148 set { maxCharactersInDocument = value; }
151 public bool IgnoreComments {
152 get { return ignoreComments; }
153 set { ignoreComments = value; }
156 public bool IgnoreProcessingInstructions {
157 get { return ignoreProcessingInstructions; }
158 set { ignoreProcessingInstructions = value; }
161 public bool IgnoreWhitespace {
162 get { return ignoreWhitespace; }
163 set { ignoreWhitespace = value; }
166 public int LineNumberOffset {
167 get { return lineNumberOffset; }
168 set { lineNumberOffset = value; }
171 public int LinePositionOffset {
172 get { return linePositionOffset; }
173 set { linePositionOffset = value; }
177 [ObsoleteAttribute("Use DtdProcessing property instead")]
179 public bool ProhibitDtd {
180 get { return prohibitDtd; }
181 set { prohibitDtd = value; }
184 // LAMESPEC: MSDN documentation says "An empty XmlNameTable
185 // object" for default value, but XmlNameTable cannot be
186 // instantiate. It actually returns null by default.
187 public XmlNameTable NameTable {
188 get { return nameTable; }
189 set { nameTable = value; }
193 public XmlSchemaSet Schemas {
195 if (schemasNeedsInitialization) {
196 schemas = new XmlSchemaSet ();
197 schemasNeedsInitialization = false;
203 schemasNeedsInitialization = false;
207 internal void OnValidationError (object o, ValidationEventArgs e)
209 if (ValidationEventHandler != null)
210 ValidationEventHandler (o, e);
211 else if (e.Severity == XmlSeverityType.Error)
215 internal void SetSchemas (XmlSchemaSet schemas)
217 this.schemas = schemas;
220 public XsValidationFlags ValidationFlags {
221 get { return validationFlags; }
222 set { validationFlags = value; }
225 public ValidationType ValidationType {
226 get { return validationType; }
227 set { validationType = value; }
231 public XmlResolver XmlResolver {
232 internal get { return xmlResolver; }
233 set { xmlResolver = value; }
237 internal void SetReadOnly ()
243 * FIXME: The .NET 4.5 runtime throws an exception when attempting to
244 * modify any of the properties after the XmlReader has been constructed.
246 void EnsureWritability ()
249 throw new InvalidOperationException ("XmlReaderSettings in read-only");
253 get { return isAsync; }
255 EnsureWritability ();