Fix in System.Data.Common namespace, use correct WriteAttributeString API (dotnet...
authorCheena Malhotra <v-chmalh@microsoft.com>
Thu, 18 Jul 2019 22:45:54 +0000 (15:45 -0700)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2019 22:45:54 +0000 (15:45 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/182bed51dec709b3b1b56a4f435e0727e5dea110

src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs
src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj
src/libraries/System.Data.Common/tests/System/Data/DataSetWriteXMLTest.cs [new file with mode: 0644]

index b025443..9ae2f0e 100644 (file)
@@ -2615,7 +2615,7 @@ namespace System.Data
                                 {
                                     string xsdTypeName = Keywords.XSD_PREFIXCOLON + XmlTreeGen.XmlDataTypeName(valuesType);
                                     _xmlw.WriteAttributeString(Keywords.XSI, Keywords.TYPE, Keywords.XSINS, xsdTypeName);
-                                    _xmlw.WriteAttributeString(Keywords.XMLNS_XSD, Keywords.XSDNS);
+                                    _xmlw.WriteAttributeString(Keywords.XSD_PREFIX, Keywords.XMLNS, Keywords.XSDNS, xsdTypeName);
                                 }
                                 if (!DataStorage.IsSqlType(valuesType))
                                 {
@@ -2934,9 +2934,6 @@ namespace System.Data
                 }
             }
 
-
-
-
             //write the attribute columns first, if any
             foreach (DataColumn col in row.Table.Columns)
             {
@@ -3044,7 +3041,7 @@ namespace System.Data
                                 {
                                     string xsdTypeName = Keywords.XSD_PREFIXCOLON + XmlTreeGen.XmlDataTypeName(valuesType);
                                     _xmlw.WriteAttributeString(Keywords.XSI, Keywords.TYPE, Keywords.XSINS, xsdTypeName);
-                                    _xmlw.WriteAttributeString(Keywords.XMLNS_XSD, Keywords.XSDNS);
+                                    _xmlw.WriteAttributeString(Keywords.XSD_PREFIX, Keywords.XMLNS, Keywords.XSDNS, xsdTypeName);
                                 }
                                 if (!DataStorage.IsSqlType(valuesType))
                                 {
index 60c5d3a..fa2f0ab 100644 (file)
@@ -55,6 +55,7 @@
     <Compile Include="System\Data\DataSetTest.cs" />
     <Compile Include="System\Data\DataSetTest2.cs" />
     <Compile Include="System\Data\DataSetTypedDataSetTest.cs" />
+    <Compile Include="System\Data\DataSetWriteXMLTest.cs" />
     <Compile Include="System\Data\DataTableCollectionTest.cs" />
     <Compile Include="System\Data\DataTableCollectionTest2.cs" />
     <Compile Include="System\Data\DataTableExtensionsTest.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataSetWriteXMLTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataSetWriteXMLTest.cs
new file mode 100644 (file)
index 0000000..c47650a
--- /dev/null
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.IO;
+using System.Xml;
+
+using Xunit;
+
+namespace System.Data.Tests
+{
+    public class DataSetWriteXmlTest
+    {
+        [Fact]
+        public void WriteSimpleAuto()
+        {
+            string sampleXml = @"<NewDataSet>
+                <xs:schema id='NewDataSet' xmlns='' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+                    <xs:element name='NewDataSet' msdata:IsDataSet='true' msdata:UseCurrentLocale='true'>
+                        <xs:complexType>
+                        <xs:choice minOccurs='0' maxOccurs='unbounded'>
+                            <xs:element name='Table'>
+                            <xs:complexType>
+                                <xs:sequence>
+                                <xs:element name='ServerName' msdata:DataType='System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' type='xs:anyType' minOccurs='0' />
+                                </xs:sequence>
+                            </xs:complexType>
+                            </xs:element>
+                        </xs:choice>
+                        </xs:complexType>
+                    </xs:element>
+                </xs:schema>
+                <Table>
+                    <ServerName xsi:type='xs:string' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>MACHINENAME</ServerName>
+                </Table>
+            </NewDataSet>";
+            DataSet ds = new DataSet();
+            System.IO.StringReader xmlSR = new System.IO.StringReader(sampleXml);
+
+            ds.ReadXml(xmlSR, XmlReadMode.ReadSchema);
+            System.Text.StringBuilder sb = new System.Text.StringBuilder();
+
+            using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, new System.Xml.XmlWriterSettings() { }))
+            {
+                ds.WriteXml(xw, System.Data.XmlWriteMode.WriteSchema);
+            }
+            Assert.Equal(@"ServerName", ds.Tables[0].Columns[0].ColumnName);
+            Assert.Equal(@"MACHINENAME", ds.Tables[0].Rows[0].Field<string>(ds.Tables[0].Columns[0]));
+
+            using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
+            {
+                ds.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);
+            }
+            Assert.Equal(@"ServerName", ds.Tables[0].Columns[0].ColumnName);
+            Assert.Equal(@"MACHINENAME", ds.Tables[0].Rows[0].Field<string>(ds.Tables[0].Columns[0]));
+        }
+    }
+}