5 // Kral Ferch <kral_ferch@hotmail.com>
11 using System.Collections;
13 using System.Xml.XPath;
17 public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
21 XmlDocument ownerDocument;
28 protected internal XmlNode (XmlDocument ownerDocument)
30 this.ownerDocument = ownerDocument;
37 public virtual XmlAttributeCollection Attributes
43 public virtual string BaseURI
45 get { throw new NotImplementedException (); }
48 public virtual XmlNodeList ChildNodes {
50 return new XmlNodeListChildren(this);
54 public virtual XmlNode FirstChild {
56 if (LastChild != null) {
57 return LastLinkedChild.NextLinkedSibling;
65 public virtual bool HasChildNodes {
66 get { return LastChild != null; }
70 public virtual string InnerText {
71 get { throw new NotImplementedException (); }
72 set { throw new NotImplementedException (); }
76 public virtual string InnerXml {
78 StringWriter sw = new StringWriter ();
79 XmlTextWriter xtw = new XmlTextWriter (sw);
83 return sw.GetStringBuilder().ToString();
86 set { throw new NotImplementedException (); }
89 public virtual bool IsReadOnly {
93 [System.Runtime.CompilerServices.IndexerName("Item")]
94 public virtual XmlElement this [string name] {
96 foreach (XmlNode node in ChildNodes) {
97 if ((node.NodeType == XmlNodeType.Element) &&
98 (node.Name == name)) {
99 return (XmlElement) node;
107 [System.Runtime.CompilerServices.IndexerName("Item")]
108 public virtual XmlElement this [string localname, string ns] {
110 foreach (XmlNode node in ChildNodes) {
111 if ((node.NodeType == XmlNodeType.Element) &&
112 (node.LocalName == localname) &&
113 (node.NamespaceURI == ns)) {
114 return (XmlElement) node;
122 public virtual XmlNode LastChild {
123 get { return LastLinkedChild; }
126 internal virtual XmlLinkedNode LastLinkedChild {
131 public abstract string LocalName { get; }
133 public abstract string Name { get; }
136 public virtual string NamespaceURI {
137 get { throw new NotImplementedException (); }
140 public virtual XmlNode NextSibling {
144 public abstract XmlNodeType NodeType { get; }
147 public virtual string OuterXml {
149 StringWriter sw = new StringWriter ();
150 XmlTextWriter xtw = new XmlTextWriter (sw);
154 return sw.GetStringBuilder().ToString();
158 public virtual XmlDocument OwnerDocument {
159 get { return ownerDocument; }
162 public virtual XmlNode ParentNode {
163 get { return parentNode; }
167 public virtual string Prefix {
168 get { throw new NotImplementedException (); }
169 set { throw new NotImplementedException (); }
172 public virtual XmlNode PreviousSibling {
177 public virtual string Value {
178 get { throw new NotImplementedException (); }
179 set { throw new NotImplementedException (); }
186 public virtual XmlNode AppendChild (XmlNode newChild)
188 if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
189 XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
190 XmlLinkedNode lastLinkedChild = LastLinkedChild;
192 newLinkedChild.parentNode = this;
194 if (lastLinkedChild != null) {
195 newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
196 lastLinkedChild.NextLinkedSibling = newLinkedChild;
198 newLinkedChild.NextLinkedSibling = newLinkedChild;
200 LastLinkedChild = newLinkedChild;
204 throw new InvalidOperationException();
208 public virtual XmlNode Clone ()
210 throw new NotImplementedException ();
213 public abstract XmlNode CloneNode (bool deep);
216 public XPathNavigator CreateNavigator ()
218 throw new NotImplementedException ();
221 public IEnumerator GetEnumerator ()
223 return new XmlNodeListChildren(this).GetEnumerator();
227 public virtual string GetNamespaceOfPrefix (string prefix)
229 throw new NotImplementedException ();
233 public virtual string GetPrefixOfNamespace (string namespaceURI)
235 throw new NotImplementedException ();
238 object ICloneable.Clone ()
243 IEnumerator IEnumerable.GetEnumerator ()
245 return GetEnumerator ();
249 public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
251 throw new NotImplementedException ();
255 public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
257 throw new NotImplementedException ();
261 public virtual void Normalize ()
263 throw new NotImplementedException ();
267 public virtual XmlNode PrependChild (XmlNode newChild)
269 throw new NotImplementedException ();
272 public virtual void RemoveAll ()
274 LastLinkedChild = null;
277 public virtual XmlNode RemoveChild (XmlNode oldChild)
279 if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute)
282 throw new ArgumentException();
284 if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
285 LastLinkedChild = null;
287 XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
288 XmlLinkedNode beforeLinkedChild = LastLinkedChild;
290 while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
291 beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
293 if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
294 throw new ArgumentException();
296 beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
297 oldLinkedChild.NextLinkedSibling = null;
303 throw new ArgumentException();
307 public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
309 throw new NotImplementedException ();
313 public virtual XmlNodeList SelectNodes (string xpath)
315 throw new NotImplementedException ();
319 public virtual XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
321 throw new NotImplementedException ();
325 public virtual XmlNode SelectSingleNode (string xpath)
327 throw new NotImplementedException ();
331 public virtual XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
333 throw new NotImplementedException ();
336 internal void SetParentNode (XmlNode parent)
342 public virtual bool Supports (string feature, string version)
344 throw new NotImplementedException ();
347 public abstract void WriteContentTo (XmlWriter w);
349 public abstract void WriteTo (XmlWriter w);