dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.05k stars 4.69k forks source link

DataSet.ReadXml reads data from incorrect tags #83507

Open vsfeedback opened 1 year ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] When XML contains data representing non-existing tables, this data is not ignored, but instead loaded into existing table if the name of the column is the same.

Reproducer:

using System.Data;
using System.Xml;

DataTable table = new DataTable("table");
table. Columns.Add("column1");
table. Columns.Add("column2");
DataSet ds = new DataSet();
ds. Tables.Add(table);

string xml = @"

  <table>
    column2_data

        not_existing_table_data

    column1_data
  </table>

";

XmlReader reader = XmlReader.Create(new StringReader(xml));
ds. ReadXml(reader);

Console.WriteLine(ds. GetXml());

Actual output is:


  <table>
    not_existing_table_data
    column2_data
  </table>

Expected output is:


  <table>
    column1_data
    column2_data
  </table>

From the docs: IgnoreSchema Ignores any inline schema and reads data into the existing DataSet schema. If any data does not match the existing schema, it is discarded (including data from differing namespaces defined for the DataSet). If the data is a DiffGram, IgnoreSchema has the same functionality as DiffGram.


Original Comments

Feedback Bot on 1/6/2023, 02:34 AM:

(private comment, text removed)


Original Solutions

(no solutions)

ghost commented 1 year ago

Tagging subscribers to this area: @roji, @ajcvickers See info in area-owners.md if you want to be subscribed.

Issue Details
_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/DataSetReadXml-reads-data-from-incorrec/10246283)._ --- [severity:It's more difficult to complete my work] When XML contains data representing non-existing tables, this data is not ignored, but instead loaded into existing table if the name of the column is the same. Reproducer: ``` using System.Data; using System.Xml; DataTable table = new DataTable("table"); table. Columns.Add("column1"); table. Columns.Add("column2"); DataSet ds = new DataSet(); ds. Tables.Add(table); string xml = @" column2_data not_existing_table_data column1_data
"; XmlReader reader = XmlReader.Create(new StringReader(xml)); ds. ReadXml(reader); Console.WriteLine(ds. GetXml()); ``` Actual output is: ``` not_existing_table_data column2_data
``` Expected output is: ``` column1_data column2_data
``` From the docs: IgnoreSchema Ignores any inline schema and reads data into the existing DataSet schema. **If any data does not match the existing schema, it is discarded** (including data from differing namespaces defined for the DataSet). If the data is a DiffGram, IgnoreSchema has the same functionality as DiffGram. --- ### Original Comments #### Feedback Bot on 1/6/2023, 02:34 AM: (private comment, text removed) --- ### Original Solutions (no solutions)
Author: vsfeedback
Assignees: -
Labels: `area-System.Data`
Milestone: -