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 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 {
176 public virtual string Value {
178 set { throw new InvalidOperationException ("This node does not have a value"); }
185 public virtual XmlNode AppendChild (XmlNode newChild)
187 if (NodeType == XmlNodeType.Document
188 || NodeType == XmlNodeType.Element
189 || NodeType == XmlNodeType.Attribute) {
190 XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild;
191 XmlLinkedNode lastLinkedChild = LastLinkedChild;
193 newLinkedChild.parentNode = this;
195 if (lastLinkedChild != null) {
196 newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
197 lastLinkedChild.NextLinkedSibling = newLinkedChild;
199 newLinkedChild.NextLinkedSibling = newLinkedChild;
201 LastLinkedChild = newLinkedChild;
205 throw new InvalidOperationException();
209 public virtual XmlNode Clone ()
211 throw new NotImplementedException ();
214 public abstract XmlNode CloneNode (bool deep);
217 public XPathNavigator CreateNavigator ()
219 throw new NotImplementedException ();
222 public IEnumerator GetEnumerator ()
224 return new XmlNodeListChildren(this).GetEnumerator();
228 public virtual string GetNamespaceOfPrefix (string prefix)
230 throw new NotImplementedException ();
234 public virtual string GetPrefixOfNamespace (string namespaceURI)
236 throw new NotImplementedException ();
239 object ICloneable.Clone ()
244 IEnumerator IEnumerable.GetEnumerator ()
246 return GetEnumerator ();
250 public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
252 throw new NotImplementedException ();
256 public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
258 throw new NotImplementedException ();
262 public virtual void Normalize ()
264 throw new NotImplementedException ();
268 public virtual XmlNode PrependChild (XmlNode newChild)
270 throw new NotImplementedException ();
273 public virtual void RemoveAll ()
275 LastLinkedChild = null;
278 public virtual XmlNode RemoveChild (XmlNode oldChild)
280 if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute)
283 throw new ArgumentException();
285 if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
286 LastLinkedChild = null;
288 XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
289 XmlLinkedNode beforeLinkedChild = LastLinkedChild;
291 while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
292 beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
294 if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
295 throw new ArgumentException();
297 beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
298 oldLinkedChild.NextLinkedSibling = null;
304 throw new ArgumentException();
308 public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
310 throw new NotImplementedException ();
314 public XmlNodeList SelectNodes (string xpath)
316 throw new NotImplementedException ();
320 public XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
322 throw new NotImplementedException ();
326 public XmlNode SelectSingleNode (string xpath)
328 throw new NotImplementedException ();
332 public XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
334 throw new NotImplementedException ();
337 internal void SetParentNode (XmlNode parent)
343 public virtual bool Supports (string feature, string version)
345 throw new NotImplementedException ();
348 public abstract void WriteContentTo (XmlWriter w);
350 public abstract void WriteTo (XmlWriter w);