Author: atsushi
Date: 2008-02-11 09:45:04 -0500 (Mon, 11 Feb 2008)
New Revision: 95438

Modified:
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XStreamingElement.cs
   trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs
Log:
2008-02-11  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * XNode.cs, XElement.cs, XStreamingElement.cs, XContainer.cs,
          XUtil.cs : one-object to one-XNode conversion is wrong. It could
          be one-or-more nodes (i.e. when object is IEnumerable).



Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog   2008-02-11 
14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog   2008-02-11 
14:45:04 UTC (rev 95438)
@@ -1,5 +1,11 @@
 2008-02-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * XNode.cs, XElement.cs, XStreamingElement.cs, XContainer.cs,
+         XUtil.cs : one-object to one-XNode conversion is wrong. It could
+         be one-or-more nodes (i.e. when object is IEnumerable).
+
+2008-02-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * XNamespace.cs : make Get() and GetName() table-based.
 
 2008-02-11  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs       
2008-02-11 14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs       
2008-02-11 14:45:04 UTC (rev 95438)
@@ -80,7 +80,12 @@
                        if (content == null)
                                return;
 
-                       XNode n = XUtil.ToNode (content);
+                       foreach (XNode n in XUtil.ToNodes (content))
+                               AddNode (n);
+               }
+
+               void AddNode (XNode n)
+               {
                        CheckChildType (n, false);
                        OnAdded (n, false);
                        n.SetOwner (this);

Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs 2008-02-11 
14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs 2008-02-11 
14:45:04 UTC (rev 95438)
@@ -455,13 +455,8 @@
                public void Save (string filename, SaveOptions options)
                {
                        XmlWriterSettings s = new XmlWriterSettings ();
-                       if ((options & SaveOptions.DisableFormatting) != 0) {
-                               // hacky!
-                               s.Indent = true;
-                               s.IndentChars = String.Empty;
-                               s.NewLineChars = String.Empty;
-                       }
-                       using (XmlWriter w = XmlWriter.Create (filename)) {
+                       s.Indent = options != SaveOptions.DisableFormatting;
+                       using (XmlWriter w = XmlWriter.Create (filename, s)) {
                                Save (w);
                        }
                }
@@ -474,13 +469,8 @@
                public void Save (TextWriter tw, SaveOptions options)
                {
                        XmlWriterSettings s = new XmlWriterSettings ();
-                       if ((options & SaveOptions.DisableFormatting) != 0) {
-                               // hacky!
-                               s.Indent = true;
-                               s.IndentChars = String.Empty;
-                               s.NewLineChars = String.Empty;
-                       }
-                       using (XmlWriter w = XmlWriter.Create (tw)) {
+                       s.Indent = options != SaveOptions.DisableFormatting;
+                       using (XmlWriter w = XmlWriter.Create (tw, s)) {
                                Save (w);
                        }
                }
@@ -639,9 +629,9 @@
 
                public void SetValue (object value)
                {
-                       XNode n = XUtil.ToNode (value);
                        RemoveNodes ();
-                       Add (n);
+                       foreach (XNode n in XUtil.ToNodes (value))
+                               Add (n);
                }
 
                internal override void OnAdded (XNode node, bool addFirst)

Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs    2008-02-11 
14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs    2008-02-11 
14:45:04 UTC (rev 95438)
@@ -82,12 +82,7 @@
                        StringWriter sw = new StringWriter ();
                        XmlWriterSettings s = new XmlWriterSettings ();
                        s.ConformanceLevel = ConformanceLevel.Auto;
-                       if ((options & SaveOptions.DisableFormatting) == 0) {
-                               // hacky!
-                               s.Indent = true;
-                               s.IndentChars = String.Empty;
-                               s.NewLineChars = String.Empty;
-                       }
+                       s.Indent = options != SaveOptions.DisableFormatting;
                        XmlWriter xw = XmlWriter.Create (sw, s);
                        WriteTo (xw);
                        xw.Close ();
@@ -98,15 +93,16 @@
                {
                        if (Parent == null)
                                throw new InvalidOperationException ();
-                       XNode n = XUtil.ToNode (content);
-                       n.SetOwner (Parent);
-                       n.previous = this;
-                       n.next = next;
-                       if (next != null)
-                               next.previous = n;
-                       next = n;
-                       if (Parent.LastNode == this)
-                               Parent.LastNode = n;
+                       foreach (XNode n in XUtil.ToNodes (content)) {
+                               n.SetOwner (Parent);
+                               n.previous = this;
+                               n.next = next;
+                               if (next != null)
+                                       next.previous = n;
+                               next = n;
+                               if (Parent.LastNode == this)
+                                       Parent.LastNode = n;
+                       }
                }
 
                public void AddAfterSelf (params object [] content)
@@ -124,15 +120,16 @@
                {
                        if (Parent == null)
                                throw new InvalidOperationException ();
-                       XNode n = XUtil.ToNode (content);
-                       n.SetOwner (Parent);
-                       n.previous = previous;
-                       n.next = this;
-                       if (previous != null)
-                               previous.next = n;
-                       previous = n;
-                       if (Parent.FirstNode == this)
-                               Parent.FirstNode = n;
+                       foreach (XNode n in XUtil.ToNodes (content)) {
+                               n.SetOwner (Parent);
+                               n.previous = previous;
+                               n.next = this;
+                               if (previous != null)
+                                       previous.next = n;
+                               previous = n;
+                               if (Parent.FirstNode == this)
+                                       Parent.FirstNode = n;
+                       }
                }
 
                public void AddBeforeSelf (params object [] content)

Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XStreamingElement.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XStreamingElement.cs        
2008-02-11 14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XStreamingElement.cs        
2008-02-11 14:45:04 UTC (rev 95438)
@@ -138,7 +138,8 @@
                                        WriteAttribute ((XAttribute) o, w);
                                else
                                        // FIXME: check node validity
-                                       XUtil.ToNode (o).WriteTo (w);
+                                       foreach (XNode n in XUtil.ToNodes (o))
+                                               n.WriteTo (w);
                        }
                }
 

Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs    2008-02-11 
14:20:23 UTC (rev 95437)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs    2008-02-11 
14:45:04 UTC (rev 95438)
@@ -60,17 +60,19 @@
                        throw new NotImplementedException ();
                }
 
-               // FIXME: this method is not enough by design.
-               public static XNode ToNode (object o)
+               public static IEnumerable<XNode> ToNodes (object o)
                {
                        XNode n = o as XNode;
                        if (n != null)
-                               return n;
-                       if (o is string)
-                               return new XText ((string) o);
-                       if (o is IEnumerable)
-                               throw new NotImplementedException ();
-                       return new XText (o.ToString ());
+                               yield return n;
+                       else if (o is string)
+                               yield return new XText ((string) o);
+                       else if (o is IEnumerable)
+                               foreach (object obj in (IEnumerable) o)
+                                       foreach (XNode nn in ToNodes (obj))
+                                               yield return nn;
+                       else
+                               yield return new XText (o.ToString ());
                }
 
                public static object Clone (object o)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to