5 // Kral Ferch <kral_ferch@hotmail.com>
11 using System.Collections;
12 using System.Xml.XPath;
16 public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
20 XmlDocument ownerDocument;
27 protected internal XmlNode (XmlDocument ownerDocument)
29 this.ownerDocument = ownerDocument;
36 public virtual XmlAttributeCollection Attributes
42 public virtual string BaseURI
44 get { throw new NotImplementedException (); }
47 public virtual XmlNodeList ChildNodes {
49 return new XmlNodeListChildren(this);
53 public virtual XmlNode FirstChild {
55 if (LastChild != null) {
56 return LastLinkedChild.NextLinkedSibling;
64 public virtual bool HasChildNodes {
65 get { return LastChild != null; }
69 public virtual string InnerText {
70 get { throw new NotImplementedException (); }
71 set { throw new NotImplementedException (); }
75 public virtual string InnerXml {
76 get { throw new NotImplementedException (); }
77 set { throw new NotImplementedException (); }
80 public virtual bool IsReadOnly {
84 [System.Runtime.CompilerServices.IndexerName("Item")]
85 public virtual XmlElement this [string name] {
87 foreach (XmlNode node in ChildNodes) {
88 if ((node.NodeType == XmlNodeType.Element) &&
89 (node.Name == name)) {
90 return (XmlElement) node;
98 [System.Runtime.CompilerServices.IndexerName("Item")]
99 public virtual XmlElement this [string localname, string ns] {
101 foreach (XmlNode node in ChildNodes) {
102 if ((node.NodeType == XmlNodeType.Element) &&
103 (node.LocalName == localname) &&
104 (node.NamespaceURI == ns)) {
105 return (XmlElement) node;
113 public virtual XmlNode LastChild {
114 get { return LastLinkedChild; }
117 internal virtual XmlLinkedNode LastLinkedChild {
122 public abstract string LocalName { get; }
124 public abstract string Name { get; }
127 public virtual string NamespaceURI {
128 get { throw new NotImplementedException (); }
131 public virtual XmlNode NextSibling {
135 public abstract XmlNodeType NodeType { get; }
138 public virtual string OuterXml {
139 get { throw new NotImplementedException (); }
142 public virtual XmlDocument OwnerDocument {
143 get { return ownerDocument; }
146 public virtual XmlNode ParentNode {
147 get { return parentNode; }
151 public virtual string Prefix {
152 get { throw new NotImplementedException (); }
153 set { throw new NotImplementedException (); }
156 public virtual XmlNode PreviousSibling {
161 public virtual string Value {
162 get { throw new NotImplementedException (); }
163 set { throw new NotImplementedException (); }
170 public virtual XmlNode AppendChild (XmlNode newChild)
172 if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
173 XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
174 XmlLinkedNode lastLinkedChild = LastLinkedChild;
176 if (lastLinkedChild != null) {
177 newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
178 lastLinkedChild.NextLinkedSibling = newLinkedChild;
180 newLinkedChild.NextLinkedSibling = newLinkedChild;
182 LastLinkedChild = newLinkedChild;
186 throw new InvalidOperationException();
190 public virtual XmlNode Clone ()
192 throw new NotImplementedException ();
195 public abstract XmlNode CloneNode (bool deep);
198 public XPathNavigator CreateNavigator ()
200 throw new NotImplementedException ();
203 public IEnumerator GetEnumerator ()
205 return new XmlNodeListChildren(this).GetEnumerator();
209 public virtual string GetNamespaceOfPrefix (string prefix)
211 throw new NotImplementedException ();
215 public virtual string GetPrefixOfNamespace (string namespaceURI)
217 throw new NotImplementedException ();
220 object ICloneable.Clone ()
225 IEnumerator IEnumerable.GetEnumerator ()
227 return GetEnumerator ();
231 public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
233 throw new NotImplementedException ();
237 public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
239 throw new NotImplementedException ();
243 public virtual void Normalize ()
245 throw new NotImplementedException ();
249 public virtual XmlNode PrependChild (XmlNode newChild)
251 throw new NotImplementedException ();
254 public virtual void RemoveAll ()
256 LastLinkedChild = null;
259 public virtual XmlNode RemoveChild (XmlNode oldChild)
261 if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute)
264 throw new ArgumentException();
266 if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
267 LastLinkedChild = null;
269 XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
270 XmlLinkedNode beforeLinkedChild = LastLinkedChild;
272 while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
273 beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
275 if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
276 throw new ArgumentException();
278 beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
279 oldLinkedChild.NextLinkedSibling = null;
285 throw new ArgumentException();
289 public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
291 throw new NotImplementedException ();
295 public virtual XmlNodeList SelectNodes (string xpath)
297 throw new NotImplementedException ();
301 public virtual XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
303 throw new NotImplementedException ();
307 public virtual XmlNode SelectSingleNode (string xpath)
309 throw new NotImplementedException ();
313 public virtual XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
315 throw new NotImplementedException ();
318 internal void SetParentNode (XmlNode parent)
324 public virtual bool Supports (string feature, string version)
326 throw new NotImplementedException ();
329 public abstract void WriteContentTo (XmlWriter w);
331 public abstract void WriteTo (XmlWriter w);