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 using System.Xml.XPath;
16 public abstract class XmlCharacterData : XmlLinkedNode
22 protected internal XmlCharacterData (string data, XmlDocument doc)
35 public virtual string Data {
39 OwnerDocument.onNodeChanging (this, this.ParentNode);
42 throw new ArgumentException ("Node is read-only.");
46 OwnerDocument.onNodeChanged (this, this.ParentNode);
50 public override string InnerText {
53 set { Data = value; } // invokes events
56 public virtual int Length {
57 get { return data != null ? data.Length : 0; }
60 public override string Value {
68 internal override XPathNodeType XPathNodeType {
69 get { return XPathNodeType.Text; }
76 public virtual void AppendData (string strData)
78 OwnerDocument.onNodeChanging (this, this.ParentNode);
80 OwnerDocument.onNodeChanged (this, this.ParentNode);
83 public virtual void DeleteData (int offset, int count)
85 OwnerDocument.onNodeChanging (this, this.ParentNode);
88 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
90 int newCount = data.Length - offset;
92 if ((offset + count) < data.Length)
95 data = data.Remove (offset, newCount);
97 OwnerDocument.onNodeChanged (this, this.ParentNode);
100 public virtual void InsertData (int offset, string strData)
102 OwnerDocument.onNodeChanging (this, this.ParentNode);
104 if ((offset < 0) || (offset > data.Length))
105 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
107 data = data.Insert(offset, strData);
109 OwnerDocument.onNodeChanged (this, this.ParentNode);
112 public virtual void ReplaceData (int offset, int count, string strData)
114 OwnerDocument.onNodeChanging (this, this.ParentNode);
116 if ((offset < 0) || (offset > data.Length))
117 throw new ArgumentOutOfRangeException ("offset", "Must be non-negative and must not be greater than the length of this instance.");
120 throw new ArgumentNullException ("strData", "Must be non-null.");
122 string newData = data.Substring (0, offset) + strData;
124 if ((offset + count) < data.Length)
125 newData += data.Substring (offset + count);
129 OwnerDocument.onNodeChanged (this, this.ParentNode);
132 public virtual string Substring (int offset, int count)
134 return data.Substring (offset, count);