2002-03-11 Duncan Mak <duncan@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlNode.cs
1 //
2 // System.Xml.XmlNode
3 //
4 // Author:
5 //   Kral Ferch <kral_ferch@hotmail.com>
6 //
7 // (C) 2002 Kral Ferch
8 //
9
10 using System;
11 using System.Collections;
12 using System.Xml.XPath;
13
14 namespace System.Xml
15 {
16         public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
17         {
18                 #region Fields
19
20                 XmlDocument ownerDocument;
21                 XmlNode parentNode;
22
23                 #endregion
24
25                 #region Constructors
26
27                 protected internal XmlNode(XmlDocument ownerDocument)
28                 {
29                         this.ownerDocument = ownerDocument;
30                 }
31
32                 #endregion
33
34                 #region Properties
35
36                 public virtual XmlAttributeCollection Attributes
37                 {
38                         get { return null; }
39                 }
40
41                 [MonoTODO]
42                 public virtual string BaseURI
43                 {
44                         get { throw new NotImplementedException (); }
45                 }
46
47                 public virtual XmlNodeList ChildNodes {
48                         get {
49                                 return new XmlNodeListChildren(LastLinkedChild);
50                         }
51                 }
52
53                 public virtual XmlNode FirstChild {
54                         get {
55                                 if (LastChild != null) {
56                                         return LastLinkedChild.NextLinkedSibling;
57                                 }
58                                 else {
59                                         return null;
60                                 }
61                         }
62                 }
63
64                 public virtual bool HasChildNodes {
65                         get { return LastChild != null; }
66                 }
67
68                 [MonoTODO]
69                 public virtual string InnerText {
70                         get { throw new NotImplementedException (); }
71                         set { throw new NotImplementedException (); }
72                 }
73
74                 [MonoTODO]
75                 public virtual string InnerXml {
76                         get { throw new NotImplementedException (); }
77                         set { throw new NotImplementedException (); }
78                 }
79
80                 [MonoTODO]
81                 public virtual bool IsReadOnly {
82                         get { throw new NotImplementedException (); }
83                 }
84
85                 [System.Runtime.CompilerServices.IndexerName("Item")]
86                 public virtual XmlElement this [string name] {
87                         get { 
88                                 foreach (XmlNode node in ChildNodes) {
89                                         if ((node.NodeType == XmlNodeType.Element) &&
90                                             (node.Name == name)) {
91                                                 return (XmlElement) node;
92                                         }
93                                 }
94
95                                 return null;
96                         }
97                 }
98
99                 [System.Runtime.CompilerServices.IndexerName("Item")]
100                 public virtual XmlElement this [string localname, string ns] {
101                         get { 
102                                 foreach (XmlNode node in ChildNodes) {
103                                         if ((node.NodeType == XmlNodeType.Element) &&
104                                             (node.LocalName == localname) && 
105                                             (node.NamespaceURI == ns)) {
106                                                 return (XmlElement) node;
107                                         }
108                                 }
109
110                                 return null;
111                         }
112                 }
113
114                 public virtual XmlNode LastChild {
115                         get { return LastLinkedChild; }
116                 }
117
118                 internal virtual XmlLinkedNode LastLinkedChild {
119                         get { return null; }
120                         set { }
121                 }
122
123                 [MonoTODO]
124                 public abstract string LocalName { get; }
125
126                 [MonoTODO]
127                 public abstract string Name     { get; }
128
129                 [MonoTODO]
130                 public virtual string NamespaceURI {
131                         get { throw new NotImplementedException (); }
132                 }
133
134                 public virtual XmlNode NextSibling {
135                         get { return null; }
136                 }
137
138                 [MonoTODO]
139                 public abstract XmlNodeType NodeType { get;     }
140
141                 [MonoTODO]
142                 public virtual string OuterXml {
143                         get { throw new NotImplementedException (); }
144                 }
145
146                 public virtual XmlDocument OwnerDocument {
147                         get { return ownerDocument; }
148                 }
149
150                 public virtual XmlNode ParentNode {
151                         get { return parentNode; }
152                 }
153
154                 [MonoTODO]
155                 public virtual string Prefix {
156                         get { throw new NotImplementedException (); }
157                         set { throw new NotImplementedException (); }
158                 }
159
160                 public virtual XmlNode PreviousSibling {
161                         get { return null; }
162                 }
163
164                 [MonoTODO]
165                 public virtual string Value {
166                         get { throw new NotImplementedException (); }
167                         set { throw new NotImplementedException (); }
168                 }
169
170                 #endregion
171
172                 #region Methods
173
174                 public virtual XmlNode AppendChild (XmlNode newChild)
175                 {
176                         if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
177                                 XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
178                                 XmlLinkedNode lastLinkedChild = LastLinkedChild;
179                                 if (lastLinkedChild != null) {
180                                         newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
181                                         lastLinkedChild.NextLinkedSibling = newLinkedChild;
182                                 } else
183                                         newLinkedChild.NextLinkedSibling = newLinkedChild;
184                                 LastLinkedChild = newLinkedChild;
185                                 return newChild;
186                         } else
187                                 throw new InvalidOperationException();
188                 }
189
190                 [MonoTODO]
191                 public virtual XmlNode Clone ()
192                 {
193                         throw new NotImplementedException ();
194                 }
195
196                 public abstract XmlNode CloneNode (bool deep);
197
198                 [MonoTODO]
199                 public XPathNavigator CreateNavigator ()
200                 {
201                         throw new NotImplementedException ();
202                 }
203
204                 [MonoTODO]
205                 public IEnumerator GetEnumerator ()
206                 {
207                         throw new NotImplementedException ();
208                 }
209
210                 [MonoTODO]
211                 public virtual string GetNamespaceOfPrefix (string prefix)
212                 {
213                         throw new NotImplementedException ();
214                 }
215
216                 [MonoTODO]
217                 public virtual string GetPrefixOfNamespace (string namespaceURI)
218                 {
219                         throw new NotImplementedException ();
220                 }
221
222                 object ICloneable.Clone ()
223                 {
224                         return Clone ();
225                 }
226
227                 IEnumerator IEnumerable.GetEnumerator ()
228                 {
229                         return GetEnumerator ();
230                 }
231
232                 [MonoTODO]
233                 public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
234                 {
235                         throw new NotImplementedException ();
236                 }
237
238                 [MonoTODO]
239                 public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
240                 {
241                         throw new NotImplementedException ();
242                 }
243
244                 [MonoTODO]
245                 public virtual void Normalize ()
246                 {
247                         throw new NotImplementedException ();
248                 }
249
250                 [MonoTODO]
251                 public virtual XmlNode PrependChild (XmlNode newChild)
252                 {
253                         throw new NotImplementedException ();
254                 }
255
256                 public virtual void RemoveAll ()
257                 {
258                         LastLinkedChild = null;
259                 }
260
261                 [MonoTODO]
262                 public virtual XmlNode RemoveChild (XmlNode oldChild)
263                 {
264                         throw new NotImplementedException ();
265                 }
266
267                 [MonoTODO]
268                 public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
269                 {
270                         throw new NotImplementedException ();
271                 }
272
273                 [MonoTODO]
274                 public virtual XmlNodeList SelectNodes (string xpath)
275                 {
276                         throw new NotImplementedException ();
277                 }
278
279                 [MonoTODO]
280                 public virtual XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
281                 {
282                         throw new NotImplementedException ();
283                 }
284
285                 [MonoTODO]
286                 public virtual XmlNode SelectSingleNode (string xpath)
287                 {
288                         throw new NotImplementedException ();
289                 }
290
291                 [MonoTODO]
292                 public virtual XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
293                 {
294                         throw new NotImplementedException ();
295                 }
296
297                 internal void SetParentNode (XmlNode parent)
298                 {
299                         parentNode = parent;
300                 }
301
302                 [MonoTODO]
303                 public virtual bool Supports (string feature, string version)
304                 {
305                         throw new NotImplementedException ();
306                 }
307
308                 [MonoTODO]
309                 public abstract void WriteContentTo (XmlWriter w);
310
311                 [MonoTODO]
312                 public abstract void WriteTo (XmlWriter w);
313
314                 #endregion
315         }
316 }