2 // System.Xml.XmlCharacterData.cs
5 // Jason Diamond <jason@injektilo.org>
6 // Kral Ferch <kral_ferch@hotmail.com>
8 // (C) 2002 Jason Diamond, Kral Ferch
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Xml.XPath;
37 public abstract class XmlCharacterData : XmlLinkedNode
43 protected internal XmlCharacterData (string data, XmlDocument doc)
56 public virtual string Data {
61 OwnerDocument.onNodeChanging (this, this.ParentNode, old, value);
65 OwnerDocument.onNodeChanged (this, this.ParentNode, old, value);
69 public override string InnerText {
72 set { Data = value; } // invokes events
75 public virtual int Length {
76 get { return data != null ? data.Length : 0; }
79 public override string Value {
87 internal override XPathNodeType XPathNodeType {
88 get { return XPathNodeType.Text; }
95 public virtual void AppendData (string strData)
97 string oldData = data;
98 string newData = data += strData;
99 OwnerDocument.onNodeChanging (this, this.ParentNode, oldData, newData);
101 OwnerDocument.onNodeChanged (this, this.ParentNode, oldData, newData);
104 public virtual void DeleteData (int offset, int count)
107 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
109 int newCount = data.Length - offset;
111 if ((offset + count) < data.Length)
114 string oldValue = data;
115 string newValue = data.Remove (offset, newCount);
117 OwnerDocument.onNodeChanging (this, this.ParentNode, oldValue, newValue);
121 OwnerDocument.onNodeChanged (this, this.ParentNode, oldValue, newValue);
124 public virtual void InsertData (int offset, string strData)
126 if ((offset < 0) || (offset > data.Length))
127 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
129 string oldData = data;
130 string newData = data.Insert(offset, strData);
132 OwnerDocument.onNodeChanging (this, this.ParentNode, oldData, newData);
136 OwnerDocument.onNodeChanged (this, this.ParentNode, oldData, newData);
139 public virtual void ReplaceData (int offset, int count, string strData)
141 if ((offset < 0) || (offset > data.Length))
142 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
145 throw new ArgumentOutOfRangeException ("count", "Must be non-negative.");
148 throw new ArgumentNullException ("strData", "Must be non-null.");
150 string oldData = data;
151 string newData = data.Substring (0, offset) + strData;
153 if ((offset + count) < data.Length)
154 newData += data.Substring (offset + count);
156 OwnerDocument.onNodeChanging (this, this.ParentNode, oldData, newData);
160 OwnerDocument.onNodeChanged (this, this.ParentNode, oldData, newData);
163 public virtual string Substring (int offset, int count)
165 if (data.Length < offset + count)
166 return data.Substring (offset);
168 return data.Substring (offset, count);