mscorlib(4.0.0.0) API with additions
XmlCharacterData.cs
1 using System.Text;
2 using System.Xml.XPath;
3 
4 namespace System.Xml
5 {
7  public abstract class XmlCharacterData : XmlLinkedNode
8  {
9  private string data;
10 
14  public override string Value
15  {
16  get
17  {
18  return Data;
19  }
20  set
21  {
22  Data = value;
23  }
24  }
25 
28  public override string InnerText
29  {
30  get
31  {
32  return Value;
33  }
34  set
35  {
36  Value = value;
37  }
38  }
39 
42  public virtual string Data
43  {
44  get
45  {
46  if (data != null)
47  {
48  return data;
49  }
50  return string.Empty;
51  }
52  set
53  {
54  XmlNode parentNode = ParentNode;
55  XmlNodeChangedEventArgs eventArgs = GetEventArgs(this, parentNode, parentNode, data, value, XmlNodeChangedAction.Change);
56  if (eventArgs != null)
57  {
58  BeforeEvent(eventArgs);
59  }
60  data = value;
61  if (eventArgs != null)
62  {
63  AfterEvent(eventArgs);
64  }
65  }
66  }
67 
70  public virtual int Length
71  {
72  get
73  {
74  if (data != null)
75  {
76  return data.Length;
77  }
78  return 0;
79  }
80  }
81 
86  protected internal XmlCharacterData(string data, XmlDocument doc)
87  : base(doc)
88  {
89  this.data = data;
90  }
91 
96  public virtual string Substring(int offset, int count)
97  {
98  int num = (data != null) ? data.Length : 0;
99  if (num > 0)
100  {
101  if (num < offset + count)
102  {
103  count = num - offset;
104  }
105  return data.Substring(offset, count);
106  }
107  return string.Empty;
108  }
109 
112  public virtual void AppendData(string strData)
113  {
114  XmlNode parentNode = ParentNode;
115  int num = (data != null) ? data.Length : 0;
116  if (strData != null)
117  {
118  num += strData.Length;
119  }
120  string newValue = new StringBuilder(num).Append(data).Append(strData).ToString();
121  XmlNodeChangedEventArgs eventArgs = GetEventArgs(this, parentNode, parentNode, data, newValue, XmlNodeChangedAction.Change);
122  if (eventArgs != null)
123  {
124  BeforeEvent(eventArgs);
125  }
126  data = newValue;
127  if (eventArgs != null)
128  {
129  AfterEvent(eventArgs);
130  }
131  }
132 
136  public virtual void InsertData(int offset, string strData)
137  {
138  XmlNode parentNode = ParentNode;
139  int num = (data != null) ? data.Length : 0;
140  if (strData != null)
141  {
142  num += strData.Length;
143  }
144  string newValue = new StringBuilder(num).Append(data).Insert(offset, strData).ToString();
145  XmlNodeChangedEventArgs eventArgs = GetEventArgs(this, parentNode, parentNode, data, newValue, XmlNodeChangedAction.Change);
146  if (eventArgs != null)
147  {
148  BeforeEvent(eventArgs);
149  }
150  data = newValue;
151  if (eventArgs != null)
152  {
153  AfterEvent(eventArgs);
154  }
155  }
156 
160  public virtual void DeleteData(int offset, int count)
161  {
162  int num = (data != null) ? data.Length : 0;
163  if (num > 0 && num < offset + count)
164  {
165  count = Math.Max(num - offset, 0);
166  }
167  string newValue = new StringBuilder(data).Remove(offset, count).ToString();
168  XmlNode parentNode = ParentNode;
169  XmlNodeChangedEventArgs eventArgs = GetEventArgs(this, parentNode, parentNode, data, newValue, XmlNodeChangedAction.Change);
170  if (eventArgs != null)
171  {
172  BeforeEvent(eventArgs);
173  }
174  data = newValue;
175  if (eventArgs != null)
176  {
177  AfterEvent(eventArgs);
178  }
179  }
180 
185  public virtual void ReplaceData(int offset, int count, string strData)
186  {
187  int num = (data != null) ? data.Length : 0;
188  if (num > 0 && num < offset + count)
189  {
190  count = Math.Max(num - offset, 0);
191  }
192  StringBuilder stringBuilder = new StringBuilder(data).Remove(offset, count);
193  string newValue = stringBuilder.Insert(offset, strData).ToString();
194  XmlNode parentNode = ParentNode;
195  XmlNodeChangedEventArgs eventArgs = GetEventArgs(this, parentNode, parentNode, data, newValue, XmlNodeChangedAction.Change);
196  if (eventArgs != null)
197  {
198  BeforeEvent(eventArgs);
199  }
200  data = newValue;
201  if (eventArgs != null)
202  {
203  AfterEvent(eventArgs);
204  }
205  }
206 
207  internal bool CheckOnData(string data)
208  {
209  return XmlCharType.Instance.IsOnlyWhitespace(data);
210  }
211 
212  internal bool DecideXPNodeTypeForTextNodes(XmlNode node, ref XPathNodeType xnt)
213  {
214  while (node != null)
215  {
216  switch (node.NodeType)
217  {
218  case XmlNodeType.SignificantWhitespace:
219  xnt = XPathNodeType.SignificantWhitespace;
220  break;
221  case XmlNodeType.Text:
222  case XmlNodeType.CDATA:
223  xnt = XPathNodeType.Text;
224  return false;
225  case XmlNodeType.EntityReference:
226  if (!DecideXPNodeTypeForTextNodes(node.FirstChild, ref xnt))
227  {
228  return false;
229  }
230  break;
231  default:
232  return false;
233  case XmlNodeType.Whitespace:
234  break;
235  }
236  node = node.NextSibling;
237  }
238  return true;
239  }
240  }
241 }
Represents an XML document. You can use this class to load, validate, edit, add, and position XML in ...
Definition: XmlDocument.cs:13
virtual void DeleteData(int offset, int count)
Removes a range of characters from the node.
virtual XmlNode ParentNode
Gets the parent of this node (for nodes that can have parents).
Definition: XmlNode.cs:60
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
unsafe StringBuilder Insert(int index, string value, int count)
Inserts one or more copies of a specified string into this instance at the specified character positi...
Definition: __Canon.cs:3
virtual void AppendData(string strData)
Appends the specified string to the end of the character data of the node.
virtual int Length
Gets the length of the data, in characters.
XmlNodeType
Specifies the type of node.
Definition: XmlNodeType.cs:5
XPathNodeType
Defines the XPath node types that can be returned from the T:System.Xml.XPath.XPathNavigator class.
Definition: XPathNodeType.cs:4
override string Value
Gets or sets the value of the node.
Provides data for the E:System.Xml.XmlDocument.NodeChanged, E:System.Xml.XmlDocument....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
virtual string Data
Contains the data of the node.
Gets the node immediately preceding or following this node.
Definition: XmlLinkedNode.cs:4
XmlNodeChangedAction
Specifies the type of node change.
static sbyte Max(sbyte val1, sbyte val2)
Returns the larger of two 8-bit signed integers.
Definition: Math.cs:581
virtual void InsertData(int offset, string strData)
Inserts the specified string at the specified character offset.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual void ReplaceData(int offset, int count, string strData)
Replaces the specified number of characters starting at the specified offset with the specified strin...
Provides text manipulation methods that are used by several classes.
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Definition: Math.cs:10
internal XmlCharacterData(string data, XmlDocument doc)
Initializes a new instance of the T:System.Xml.XmlCharacterData class.
Represents a single node in the XML document.
Definition: XmlNode.cs:13
virtual string Substring(int offset, int count)
Retrieves a substring of the full string from the specified range.
StringBuilder Remove(int startIndex, int length)
Removes the specified range of characters from this instance.
override string InnerText
Gets or sets the concatenated values of the node and all the children of the node.