DataSet.writeXml does not write empty tag if field is empty C #

I want to create the XML of my DataSet using the .writeXml function. If the record in my DataSet was empty, I would like to have an empty tag instead of a missing tag:

an example of how it should look if John was not of age:

  <MyDataSet>
    <ID>8613458</ID>
    <AW_ID>37534778</AW_ID>
    <NAME>Peter</NAME>
    <AGE>22</AGE>
  </MyDataSet>
  <MyDataSet>
    <ID>8613459</ID>
    <AW_ID>37534779</AW_ID>
    <NAME>John</NAME>
    <AGE></AGE>
  </MyDataSet>

An example of what it looks like right now:

  <MyDataSet>
    <ID>8613458</ID>
    <AW_ID>37534778</AW_ID>
    <NAME>Peter</NAME>
    <AGE>22</AGE>
  </MyDataSet>
  <MyDataSet>
    <ID>8613459</ID>
    <AW_ID>37534779</AW_ID>
    <NAME>John</NAME>
  </MyDataSet>

Do you know what I need to do? Thank you for your help!

+3
source share
2 answers

, , , NULL, NULL .
, , NULL , XML, .

+1

WriteXmlSchema ( ReadXmlSchema) . , NULL XML, .

using (SqlCommand sqlCommand = new SqlCommand(QUERY, CONNECTION))
{
    SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand);
    DataSet dataSet = new DataSet();
    dataAdapter.Fill(dataSet);
    dataSet.WriteXmlSchema(@"C:\TEMP\Schema.xsd");
    dataSet.Tables[0].WriteXml(@"C:\TEMP\Output.xml");
}

: XML

0

Source: https://habr.com/ru/post/1747185/


All Articles