touchups on XmlTextWriter attribute writing.
[mono.git] / mcs / class / System.XML / System.Xml / XmlNode.cs
index 88bddc770e8f3f7c8ebf56b80670155d341b2451..c7f894a6a56a0b16c81763c4db319b631c9b88f3 100644 (file)
@@ -9,6 +9,7 @@
 
 using System;
 using System.Collections;
+using System.IO;
 using System.Xml.XPath;
 
 namespace System.Xml
@@ -24,7 +25,7 @@ namespace System.Xml
 
                #region Constructors
 
-               protected internal XmlNode(XmlDocument ownerDocument)
+               protected internal XmlNode (XmlDocument ownerDocument)
                {
                        this.ownerDocument = ownerDocument;
                }
@@ -46,7 +47,7 @@ namespace System.Xml
 
                public virtual XmlNodeList ChildNodes {
                        get {
-                               return new XmlNodeListChildren(LastLinkedChild);
+                               return new XmlNodeListChildren(this);
                        }
                }
 
@@ -71,15 +72,22 @@ namespace System.Xml
                        set { throw new NotImplementedException (); }
                }
 
-               [MonoTODO]
+               [MonoTODO("Setter.")]
                public virtual string InnerXml {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               StringWriter sw = new StringWriter ();
+                               XmlTextWriter xtw = new XmlTextWriter (sw);
+
+                               WriteContentTo(xtw);
+
+                               return sw.GetStringBuilder().ToString();
+                       }
+
                        set { throw new NotImplementedException (); }
                }
 
-               [MonoTODO]
                public virtual bool IsReadOnly {
-                       get { throw new NotImplementedException (); }
+                       get { return false; }
                }
 
                [System.Runtime.CompilerServices.IndexerName("Item")]
@@ -120,10 +128,8 @@ namespace System.Xml
                        set { }
                }
 
-               [MonoTODO]
                public abstract string LocalName { get; }
 
-               [MonoTODO]
                public abstract string Name     { get; }
 
                [MonoTODO]
@@ -135,12 +141,18 @@ namespace System.Xml
                        get { return null; }
                }
 
-               [MonoTODO]
                public abstract XmlNodeType NodeType { get;     }
 
                [MonoTODO]
                public virtual string OuterXml {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               StringWriter sw = new StringWriter ();
+                               XmlTextWriter xtw = new XmlTextWriter (sw);
+
+                               WriteTo(xtw);
+
+                               return sw.GetStringBuilder().ToString();
+                       }
                }
 
                public virtual XmlDocument OwnerDocument {
@@ -161,10 +173,9 @@ namespace System.Xml
                        get { return null; }
                }
 
-               [MonoTODO]
                public virtual string Value {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return null; }
+                       set { throw new InvalidOperationException ("This node does not have a value"); }
                }
 
                #endregion
@@ -173,15 +184,22 @@ namespace System.Xml
 
                public virtual XmlNode AppendChild (XmlNode newChild)
                {
-                       if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
-                               XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
+                       if (NodeType == XmlNodeType.Document
+                           || NodeType == XmlNodeType.Element
+                           || NodeType == XmlNodeType.Attribute) {
+                               XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild;
                                XmlLinkedNode lastLinkedChild = LastLinkedChild;
+
+                               newLinkedChild.parentNode = this;
+                               
                                if (lastLinkedChild != null) {
                                        newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
                                        lastLinkedChild.NextLinkedSibling = newLinkedChild;
                                } else
                                        newLinkedChild.NextLinkedSibling = newLinkedChild;
+                               
                                LastLinkedChild = newLinkedChild;
+
                                return newChild;
                        } else
                                throw new InvalidOperationException();
@@ -201,10 +219,9 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public IEnumerator GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return new XmlNodeListChildren(this).GetEnumerator();
                }
 
                [MonoTODO]
@@ -258,10 +275,33 @@ namespace System.Xml
                        LastLinkedChild = null;
                }
 
-               [MonoTODO]
                public virtual XmlNode RemoveChild (XmlNode oldChild)
                {
-                       throw new NotImplementedException ();
+                       if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) 
+                       {
+                               if (IsReadOnly)
+                                       throw new ArgumentException();
+
+                               if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
+                                       LastLinkedChild = null;
+                               else {
+                                       XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
+                                       XmlLinkedNode beforeLinkedChild = LastLinkedChild;
+                                       
+                                       while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
+                                               beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
+
+                                       if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
+                                               throw new ArgumentException();
+
+                                       beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
+                                       oldLinkedChild.NextLinkedSibling = null;
+                                }
+
+                               return oldChild;
+                       } 
+                       else
+                               throw new ArgumentException();
                }
 
                [MonoTODO]
@@ -305,10 +345,8 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public abstract void WriteContentTo (XmlWriter w);
 
-               [MonoTODO]
                public abstract void WriteTo (XmlWriter w);
 
                #endregion