Files
mono/mcs/class/System/System.Configuration/ConfigXmlDocument.cs
T
Duncan Mak 24f5ef2c44 Add MIT license to System.dll
svn path=/trunk/mcs/; revision=30054
2004-06-21 18:02:11 +00:00

260 lines
5.4 KiB
C#

//
// System.Configuration.ConfigXmlDocument
//
// Authors:
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
#if (XML_DEP)
using System.Xml;
namespace System.Configuration
{
public sealed class ConfigXmlDocument : XmlDocument, IConfigXmlNode
{
XmlTextReader reader;
string fileName;
int lineNumber;
public override XmlAttribute CreateAttribute (string prefix,
string localName,
string namespaceUri)
{
return new ConfigXmlAttribute (this, prefix, localName, namespaceUri);
}
public override XmlCDataSection CreateCDataSection (string data)
{
return new ConfigXmlCDataSection (this, data);
}
public override XmlComment CreateComment (string comment)
{
return new ConfigXmlComment (this, comment);
}
public override XmlElement CreateElement (string prefix, string localName, string namespaceUri)
{
return new ConfigXmlElement (this, prefix, localName, namespaceUri);
}
public override XmlSignificantWhitespace CreateSignificantWhitespace (string data)
{
return base.CreateSignificantWhitespace (data);
}
public override XmlText CreateTextNode (string text)
{
return new ConfigXmlText (this, text);
}
public override XmlWhitespace CreateWhitespace (string data)
{
return base.CreateWhitespace (data);
}
public override void Load (string filename)
{
XmlTextReader rd = new XmlTextReader (filename);
rd.MoveToContent ();
LoadSingleElement (filename, rd);
}
public void LoadSingleElement (string filename, XmlTextReader sourceReader)
{
fileName = filename;
lineNumber = sourceReader.LineNumber;
string xml = sourceReader.ReadOuterXml();
reader = new XmlTextReader (new StringReader (xml), sourceReader.NameTable);
Load (reader);
reader.Close ();
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
//
// Wrappers for Xml* that just provide file name and line number addition
//
class ConfigXmlAttribute : XmlAttribute, IConfigXmlNode
{
string fileName;
int lineNumber;
public ConfigXmlAttribute (ConfigXmlDocument document,
string prefix,
string localName,
string namespaceUri)
: base (prefix, localName, namespaceUri, document)
{
fileName = document.Filename;
lineNumber = document.LineNumber;
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
}
class ConfigXmlCDataSection : XmlCDataSection, IConfigXmlNode
{
string fileName;
int lineNumber;
public ConfigXmlCDataSection (ConfigXmlDocument document, string data)
: base (data, document)
{
fileName = document.Filename;
lineNumber = document.LineNumber;
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
}
class ConfigXmlComment : XmlComment, IConfigXmlNode
{
string fileName;
int lineNumber;
public ConfigXmlComment (ConfigXmlDocument document, string comment)
: base (comment, document)
{
fileName = document.Filename;
lineNumber = document.LineNumber;
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
}
class ConfigXmlElement : XmlElement, IConfigXmlNode
{
string fileName;
int lineNumber;
public ConfigXmlElement (ConfigXmlDocument document,
string prefix,
string localName,
string namespaceUri)
: base (prefix, localName, namespaceUri, document)
{
fileName = document.Filename;
lineNumber = document.LineNumber;
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
}
class ConfigXmlText : XmlText, IConfigXmlNode
{
string fileName;
int lineNumber;
public ConfigXmlText (ConfigXmlDocument document, string data)
: base (data, document)
{
fileName = document.Filename;
lineNumber = document.LineNumber;
}
public string Filename
{
get {
return fileName;
}
}
public int LineNumber
{
get {
return lineNumber;
}
}
}
}
}
#endif