mscorlib(4.0.0.0) API with additions
XmlText.cs
1 using System.Xml.XPath;
2 
3 namespace System.Xml
4 {
6  public class XmlText : XmlCharacterData
7  {
10  public override string Name => OwnerDocument.strTextName;
11 
14  public override string LocalName => OwnerDocument.strTextName;
15 
18  public override XmlNodeType NodeType => XmlNodeType.Text;
19 
22  public override XmlNode ParentNode
23  {
24  get
25  {
26  switch (base.parentNode.NodeType)
27  {
28  case XmlNodeType.Document:
29  return null;
30  case XmlNodeType.Text:
31  case XmlNodeType.CDATA:
32  case XmlNodeType.Whitespace:
33  case XmlNodeType.SignificantWhitespace:
34  {
35  XmlNode parentNode = base.parentNode.parentNode;
36  while (parentNode.IsText)
37  {
38  parentNode = parentNode.parentNode;
39  }
40  return parentNode;
41  }
42  default:
43  return base.parentNode;
44  }
45  }
46  }
47 
50  public override string Value
51  {
52  get
53  {
54  return Data;
55  }
56  set
57  {
58  Data = value;
59  XmlNode parentNode = base.parentNode;
60  if (parentNode != null && parentNode.NodeType == XmlNodeType.Attribute)
61  {
62  XmlUnspecifiedAttribute xmlUnspecifiedAttribute = parentNode as XmlUnspecifiedAttribute;
63  if (xmlUnspecifiedAttribute != null && !xmlUnspecifiedAttribute.Specified)
64  {
65  xmlUnspecifiedAttribute.SetSpecified(f: true);
66  }
67  }
68  }
69  }
70 
71  internal override XPathNodeType XPNodeType => XPathNodeType.Text;
72 
73  internal override bool IsText => true;
74 
77  public override XmlNode PreviousText
78  {
79  get
80  {
81  if (parentNode.IsText)
82  {
83  return parentNode;
84  }
85  return null;
86  }
87  }
88 
89  internal XmlText(string strData)
90  : this(strData, null)
91  {
92  }
93 
97  protected internal XmlText(string strData, XmlDocument doc)
98  : base(strData, doc)
99  {
100  }
101 
106  public override XmlNode CloneNode(bool deep)
107  {
109  }
110 
114  public virtual XmlText SplitText(int offset)
115  {
116  XmlNode parentNode = ParentNode;
117  int length = Length;
118  if (offset > length)
119  {
120  throw new ArgumentOutOfRangeException("offset");
121  }
122  if (parentNode == null)
123  {
124  throw new InvalidOperationException(Res.GetString("Xdom_TextNode_SplitText"));
125  }
126  int count = length - offset;
127  string text = Substring(offset, count);
128  DeleteData(offset, count);
129  XmlText xmlText = OwnerDocument.CreateTextNode(text);
130  parentNode.InsertAfter(xmlText, this);
131  return xmlText;
132  }
133 
136  public override void WriteTo(XmlWriter w)
137  {
138  w.WriteString(Data);
139  }
140 
143  public override void WriteContentTo(XmlWriter w)
144  {
145  }
146  }
147 }
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 XmlDocument OwnerDocument
Gets the T:System.Xml.XmlDocument to which this node belongs.
Definition: XmlNode.cs:104
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override void WriteContentTo(XmlWriter w)
Saves all the children of the node to the specified T:System.Xml.XmlWriter. XmlText nodes do not have...
Definition: XmlText.cs:143
virtual int Length
Gets the length of the data, in characters.
XmlNodeType
Specifies the type of node.
Definition: XmlNodeType.cs:5
abstract void WriteString(string text)
When overridden in a derived class, writes the given text content.
override void WriteTo(XmlWriter w)
Saves the node to the specified T:System.Xml.XmlWriter.
Definition: XmlText.cs:136
XPathNodeType
Defines the XPath node types that can be returned from the T:System.Xml.XPath.XPathNavigator class.
Definition: XPathNodeType.cs:4
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: XmlWriter.cs:12
override XmlNodeType NodeType
Gets the type of the current node.
Definition: XmlText.cs:18
override XmlNode PreviousText
Gets the text node that immediately precedes this node.
Definition: XmlText.cs:78
virtual XmlText CreateTextNode(string text)
Creates an T:System.Xml.XmlText with the specified text.
Definition: XmlDocument.cs:942
virtual XmlText SplitText(int offset)
Splits the node into two nodes at the specified offset, keeping both in the tree as siblings.
Definition: XmlText.cs:114
override string Name
Gets the qualified name of the node.
Definition: XmlText.cs:10
virtual string Data
Contains the data of the node.
override string Value
Gets or sets the value of the node.
Definition: XmlText.cs:51
override XmlNode ParentNode
Gets the parent of this node (for nodes that can have parents).
Definition: XmlText.cs:23
Represents the text content of an element or attribute.
Definition: XmlText.cs:6
internal XmlText(string strData, XmlDocument doc)
Initializes a new instance of the T:System.Xml.XmlText class.
Definition: XmlText.cs:97
Provides text manipulation methods that are used by several classes.
The exception that is thrown when a method call is invalid for the object's current state.
override XmlNode CloneNode(bool deep)
Creates a duplicate of this node.
Definition: XmlText.cs:106
virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
Inserts the specified node immediately after the specified reference node.
Definition: XmlNode.cs:623
override string LocalName
Gets the local name of the node.
Definition: XmlText.cs:14
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.
abstract XmlNodeType NodeType
Gets the type of the current node, when overridden in a derived class.
Definition: XmlNode.cs:53