2002-12-19 Ville Palo <vi64pa@koti.soon.fi>
authorVille Palo <ville@mono-cvs.ximian.com>
Thu, 19 Dec 2002 20:14:13 +0000 (20:14 -0000)
committerVille Palo <ville@mono-cvs.ximian.com>
Thu, 19 Dec 2002 20:14:13 +0000 (20:14 -0000)
* DataSet.cs Implemented ReadXml with XmlReadMode.ReadSchema

svn path=/trunk/mcs/; revision=9775

mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataSet.cs

index c89dd14dd47384929e123eb76d9a7442f096c5a5..cd73e84ae865c901a974445d06bb79d9a590f580 100644 (file)
@@ -1,3 +1,7 @@
+2002-12-19  Ville Palo <vi64pa@koti.soon.fi>\r
+\r
+       * DataSet.cs Implemented ReadXml with XmlReadMode.ReadSchema\r
+       \r
 2002-12-18  Ville Palo <vi64pa@koti.soon.fi>\r
 \r
        * DataSet.cs: Started to implement ReadXml-methods.\r
index 413ad5721cfc7751ead07f708f59509cbc13e3b9..2b3d80b7f7551efdb1ab272f9cd38110d7baae9c 100644 (file)
@@ -414,7 +414,7 @@ namespace System.Data {
                         *  If document is diffgram we will use diffgram
                        \*/
                        if (r.LocalName == "diffgram")
-                               ReadXml (r, XmlReadMode.DiffGram);
+                               return ReadXml (r, XmlReadMode.DiffGram);
 
                        /*\
                         *  If we already have a schema, or the document 
@@ -423,17 +423,14 @@ namespace System.Data {
 
                        // FIXME: is this always true: "if we have tables we have to have schema also"
                        if (Tables.Count > 0)                           
-                               ReadXml (r, XmlReadMode.ReadSchema);
+                               return ReadXml (r, XmlReadMode.ReadSchema);
 
                        /*\
                         *  If we dont have a schema yet and document 
                         *  contains no inline-schema  mode is XmlReadMode.InferSchema
                        \*/
 
-                       ReadXml (r, XmlReadMode.InferSchema);
-
-
-                       return XmlReadMode.Auto;
+                       return ReadXml (r, XmlReadMode.InferSchema);
                }
 
                public XmlReadMode ReadXml (Stream stream, XmlReadMode mode)
@@ -461,11 +458,12 @@ namespace System.Data {
                                case XmlReadMode.DiffGram:
                                        break;
                                case XmlReadMode.ReadSchema:
+                                       readMode = XmlReadMode.ReadSchema;
+                                       ReadXmlReadSchema (reader);                                     
                                        break;
                                case XmlReadMode.InferSchema:
                                        readMode = XmlReadMode.InferSchema;
                                        ReadXmlInferSchemaMode (reader);
-                                      
                                        break;
                                default:
                                        break;
@@ -538,7 +536,7 @@ namespace System.Data {
                        while (reader.Read ()) {
 
                                // skip possible inline-schema
-                               if (String.Compare (reader.LocalName, "schema", true) == 0) {
+                               if (String.Compare (reader.LocalName, "schema", true) == 0 && reader.NodeType == XmlNodeType.Element) {
                                        while (reader.Read () && (reader.NodeType != XmlNodeType.EndElement 
                                                                  || String.Compare (reader.LocalName, "schema", true) != 0));
                                }
@@ -592,6 +590,44 @@ namespace System.Data {
                        }                       
                }
 
+               [MonoTODO]
+               private void ReadXmlReadSchema (XmlReader reader)
+               {
+                       /*\
+                        *  Reads any inline schema, but an exception is thrown 
+                        *  if any tables in the inline schema already exist in the DataSet.
+                       \*/
+
+                       reader.MoveToContent ();
+
+                       while (reader.Read ()) {
+
+                               // FIXME: possible inline-schema should be readed here
+                               if (String.Compare (reader.LocalName, "schema", true) == 0 && reader.NodeType == XmlNodeType.Element) {
+                                       ReadXmlSchema (reader);
+                               }
+
+                               // find table
+                               if (reader.NodeType == XmlNodeType.Element && Tables.Contains (reader.LocalName)) {
+                                       
+                                       DataTable table = Tables [reader.LocalName];
+                                       DataRow row = table.NewRow ();
+                                       do {
+                                               if (reader.NodeType == XmlNodeType.Element && 
+                                                   table.Columns.Contains (reader.LocalName)) {
+                                                       string columName = reader.LocalName;
+                                                       reader.Read ();
+                                                       row [columName] = reader.Value;
+                                               }
+
+                                       } while (table.TableName != reader.LocalName 
+                                                                   || reader.NodeType != XmlNodeType.EndElement);
+                                       
+                                       table.Rows.Add (row);
+                               }
+                       }
+               }
+
                #endregion // Private ReadXml-methods
 
                #region Private Xml Serialisation