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.Security;
32 using System.Security.Permissions;
37 namespace System.Configuration
39 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
40 public sealed class ConfigXmlDocument : XmlDocument, IConfigXmlNode
46 public override XmlAttribute CreateAttribute (string prefix,
50 return new ConfigXmlAttribute (this, prefix, localName, namespaceUri);
53 public override XmlCDataSection CreateCDataSection (string data)
55 return new ConfigXmlCDataSection (this, data);
58 public override XmlComment CreateComment (string comment)
60 return new ConfigXmlComment (this, comment);
63 public override XmlElement CreateElement (string prefix, string localName, string namespaceUri)
65 return new ConfigXmlElement (this, prefix, localName, namespaceUri);
68 public override XmlSignificantWhitespace CreateSignificantWhitespace (string data)
70 return base.CreateSignificantWhitespace (data);
73 public override XmlText CreateTextNode (string text)
75 return new ConfigXmlText (this, text);
78 public override XmlWhitespace CreateWhitespace (string data)
80 return base.CreateWhitespace (data);
83 public override void Load (string filename)
85 XmlTextReader rd = new XmlTextReader (filename);
87 LoadSingleElement (filename, rd);
90 public void LoadSingleElement (string filename, XmlTextReader sourceReader)
93 lineNumber = sourceReader.LineNumber;
94 string xml = sourceReader.ReadOuterXml();
95 reader = new XmlTextReader (new StringReader (xml), sourceReader.NameTable);
100 public string Filename
103 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
104 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
110 public int LineNumber
118 // Wrappers for Xml* that just provide file name and line number addition
120 class ConfigXmlAttribute : XmlAttribute, IConfigXmlNode
125 public ConfigXmlAttribute (ConfigXmlDocument document,
129 : base (prefix, localName, namespaceUri, document)
131 fileName = document.fileName;
132 lineNumber = document.LineNumber;
135 public string Filename
138 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
139 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
145 public int LineNumber
153 class ConfigXmlCDataSection : XmlCDataSection, IConfigXmlNode
158 public ConfigXmlCDataSection (ConfigXmlDocument document, string data)
159 : base (data, document)
161 fileName = document.fileName;
162 lineNumber = document.LineNumber;
165 public string Filename
168 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
169 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
175 public int LineNumber
183 class ConfigXmlComment : XmlComment, IConfigXmlNode
188 public ConfigXmlComment (ConfigXmlDocument document, string comment)
189 : base (comment, document)
191 fileName = document.fileName;
192 lineNumber = document.LineNumber;
195 public string Filename
198 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
199 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
205 public int LineNumber
213 class ConfigXmlElement : XmlElement, IConfigXmlNode
218 public ConfigXmlElement (ConfigXmlDocument document,
222 : base (prefix, localName, namespaceUri, document)
224 fileName = document.fileName;
225 lineNumber = document.LineNumber;
228 public string Filename
231 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
232 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
238 public int LineNumber
246 class ConfigXmlText : XmlText, IConfigXmlNode
251 public ConfigXmlText (ConfigXmlDocument document, string data)
252 : base (data, document)
254 fileName = document.fileName;
255 lineNumber = document.LineNumber;
258 public string Filename
261 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
262 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
268 public int LineNumber