2 // System.Configuration.ConfigXmlDocument
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using System.Configuration.Internal;
34 using System.Security;
35 using System.Security.Permissions;
40 #pragma warning disable 618
42 namespace System.Configuration
44 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
45 public sealed class ConfigXmlDocument : XmlDocument, IConfigXmlNode
54 public override XmlAttribute CreateAttribute (string prefix,
58 return new ConfigXmlAttribute (this, prefix, localName, namespaceUri);
61 public override XmlCDataSection CreateCDataSection (string data)
63 return new ConfigXmlCDataSection (this, data);
66 public override XmlComment CreateComment (string data)
68 return new ConfigXmlComment (this, data);
71 public override XmlElement CreateElement (string prefix, string localName, string namespaceUri)
73 return new ConfigXmlElement (this, prefix, localName, namespaceUri);
76 public override XmlSignificantWhitespace CreateSignificantWhitespace (string data)
78 return base.CreateSignificantWhitespace (data);
81 public override XmlText CreateTextNode (string text)
83 return new ConfigXmlText (this, text);
86 public override XmlWhitespace CreateWhitespace (string data)
88 return base.CreateWhitespace (data);
91 public override void Load (string filename)
93 XmlTextReader rd = new XmlTextReader (filename);
96 LoadSingleElement (filename, rd);
102 public void LoadSingleElement (string filename, XmlTextReader sourceReader)
105 lineNumber = sourceReader.LineNumber;
106 string xml = sourceReader.ReadOuterXml();
107 reader = new XmlTextReader (new StringReader (xml), sourceReader.NameTable);
112 public string Filename
115 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
116 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
122 public int LineNumber
129 #if CONFIGURATION_DEP
130 string System.Configuration.Internal.IConfigErrorInfo.Filename {
131 get { return Filename; }
134 int System.Configuration.Internal.IConfigErrorInfo.LineNumber {
135 get { return LineNumber; }
139 string IConfigXmlNode.Filename {
140 get { return Filename; }
143 int IConfigXmlNode.LineNumber {
144 get { return LineNumber; }
148 // Wrappers for Xml* that just provide file name and line number addition
150 class ConfigXmlAttribute : XmlAttribute, IConfigXmlNode
151 #if CONFIGURATION_DEP
158 public ConfigXmlAttribute (ConfigXmlDocument document,
162 : base (prefix, localName, namespaceUri, document)
164 fileName = document.fileName;
165 lineNumber = document.LineNumber;
168 public string Filename
171 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
172 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
178 public int LineNumber
186 class ConfigXmlCDataSection : XmlCDataSection, IConfigXmlNode
187 #if CONFIGURATION_DEP
194 public ConfigXmlCDataSection (ConfigXmlDocument document, string data)
195 : base (data, document)
197 fileName = document.fileName;
198 lineNumber = document.LineNumber;
201 public string Filename
204 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
205 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
211 public int LineNumber
219 class ConfigXmlComment : XmlComment, IConfigXmlNode
224 public ConfigXmlComment (ConfigXmlDocument document, string comment)
225 : base (comment, document)
227 fileName = document.fileName;
228 lineNumber = document.LineNumber;
231 public string Filename
234 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
235 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
241 public int LineNumber
249 class ConfigXmlElement : XmlElement, IConfigXmlNode
250 #if CONFIGURATION_DEP
257 public ConfigXmlElement (ConfigXmlDocument document,
261 : base (prefix, localName, namespaceUri, document)
263 fileName = document.fileName;
264 lineNumber = document.LineNumber;
267 public string Filename
270 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
271 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
277 public int LineNumber
285 class ConfigXmlText : XmlText, IConfigXmlNode
286 #if CONFIGURATION_DEP
293 public ConfigXmlText (ConfigXmlDocument document, string data)
294 : base (data, document)
296 fileName = document.fileName;
297 lineNumber = document.LineNumber;
300 public string Filename
303 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
304 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
310 public int LineNumber