importing messaging-2008 branch to trunk [continued]
[mono.git] / mcs / class / System.Data / System.Data / XmlDataReader.cs
index 8cc749699f4ce70ea36fb21da169d8ab2989ae7a..f687cdeae1ca9c2715577f7dd3f249073561eb8c 100644 (file)
@@ -26,6 +26,7 @@ using System;
 using System.IO;\r
 using System.Data;\r
 using System.Xml;\r
+using System.Xml.Serialization;\r
 \r
 \r
 namespace System.Data\r
@@ -129,7 +130,6 @@ namespace System.Data
 \r
                        // No need to check DataSetName. In fact, it is ignored.\r
 \r
-                       bool ambiguous = false;\r
                        DataTable dt = dataset.Tables [local];\r
                        if (dt == null)\r
                                return true;\r
@@ -193,7 +193,11 @@ namespace System.Data
                        // Consume attributes\r
                        if (reader.MoveToFirstAttribute ()) {\r
                                do {\r
-                                       if (reader.NamespaceURI == XmlConstants.XmlnsNS)\r
+                                       if (reader.NamespaceURI == XmlConstants.XmlnsNS\r
+#if NET_2_0\r
+                                       || reader.NamespaceURI == XmlConstants.XmlNS\r
+#endif\r
+                                               )\r
                                                continue;\r
                                        ReadElementAttribute (row);\r
                                } while (reader.MoveToNextAttribute ());\r
@@ -293,7 +297,27 @@ namespace System.Data
 \r
                                bool wasEmpty = reader.IsEmptyElement;\r
                                int depth = reader.Depth;\r
-                               row [col] = StringToObject (col.DataType, reader.ReadElementString ());\r
+\r
+                               if (typeof (IXmlSerializable).IsAssignableFrom (col.DataType)) {\r
+#if NET_2_0\r
+                                       try {\r
+                                               // NOTE: ReadElementString works fine with proper XML with CDATA etc,\r
+                                               // however doesn't behave well with XMLs like the one in \r
+                                               // https://bugzilla.novell.com/show_bug.cgi?id=377146 which is \r
+                                               // apparently supported by MS.NET - to maintain compatibility,\r
+                                               // Try reading the element content as an object type\r
+                                               row [col] = reader.ReadContentAsObject ();\r
+                                       } catch {\r
+#endif\r
+                                               // XML is not in accordance to expected standards, try reading the content as an xml doc\r
+                                               row [col] = reader.ReadInnerXml ();\r
+#if NET_2_0\r
+                                       }\r
+#endif\r
+                               } else {\r
+                                       row [col] = StringToObject (col.DataType, reader.ReadElementString ());\r
+                               }\r
+                                       \r
                                if (!wasEmpty && reader.Depth > depth) {\r
                                // This means, instance does not match with\r
                                // the schema (because the instance element\r
@@ -367,6 +391,7 @@ namespace System.Data
                        if (type == typeof (TimeSpan)) return XmlConvert.ToTimeSpan (value);\r
                        if (type == typeof (Guid)) return XmlConvert.ToGuid (value);\r
                        if (type == typeof (byte[])) return Convert.FromBase64String (value);\r
+                       if (type == typeof (System.Type)) return System.Type.GetType (value);\r
 \r
                        return Convert.ChangeType (value, type);\r
                }\r