C# 如何为数据集中的空数据表生成XML?

C# 如何为数据集中的空数据表生成XML?,c#,xml,datatable,C#,Xml,Datatable,生成的XML中缺少空的数据表 这是生成它的代码: servicedataset.WriteXml(targetFile,XmlWriteMode.IgnoreSchema) 数据集中没有为空数据表生成XML标记 我需要XML来拥有数据集中的所有数据表。 有没有办法包含空的数据表?我正试图将数据集的xml导入Excel。但是这样做会产生一些问题,比如带有空值的表和列会丢失。我找到的解决方案是创建一个xsd文件和一个xml文件 将xsd映射到excel,然后使用xml导入数据 我使用以下代码生成xm

生成的XML中缺少空的数据表

这是生成它的代码:

servicedataset.WriteXml(targetFile,XmlWriteMode.IgnoreSchema)

数据集中没有为空数据表生成XML标记

我需要XML来拥有数据集中的所有数据表。
有没有办法包含空的数据表?

我正试图将数据集的xml导入Excel。但是这样做会产生一些问题,比如带有空值的表和列会丢失。我找到的解决方案是创建一个xsd文件和一个xml文件

将xsd映射到excel,然后使用xml导入数据

我使用以下代码生成xml和xsd:

// Build xml file path (target)
string targetFile = "";
targetFile = Path.Combine(this.txtTargetPath.Text, _servicedDataSet.DataSetName + ".xml");

// To import the xml file in Excel two files are being generated: xml and xsd. 
// When mapping the xml file to excel the columns and tables with null values goes missing.
// Mapping the xsd file solves the problem. Therefore, we are generating two separate xml and xsd files.
// xsd for the structure and xml for the data.

if (chkSchema.Checked == true)
{
    // Build xsd file path (xsdtarget)
    string xsdtargetFile = "";
    xsdtargetFile = Path.Combine(this.txtTargetPath.Text, _servicedDataSet.DataSetName + ".xsd");

    // Publish the dataset as XML
    _servicedDataSet.WriteXml(targetFile, XmlWriteMode.IgnoreSchema);

    // Creating the xsd file from the dataset.
    string schema = _servicedDataSet.GetXmlSchema();

    // Encoding utf-16 is not compatible with Excel. Changing utf-16 to utf-8 sorts the problem
    string result = schema.Replace("utf-16", "utf-8");
    System.IO.File.WriteAllText(xsdtargetFile, result);
}

我试图将数据集的xml导入Excel。但是这样做会产生一些问题,比如带有空值的表和列会丢失。我找到的解决方案是创建一个xsd文件和一个xml文件

将xsd映射到excel,然后使用xml导入数据

我使用以下代码生成xml和xsd:

// Build xml file path (target)
string targetFile = "";
targetFile = Path.Combine(this.txtTargetPath.Text, _servicedDataSet.DataSetName + ".xml");

// To import the xml file in Excel two files are being generated: xml and xsd. 
// When mapping the xml file to excel the columns and tables with null values goes missing.
// Mapping the xsd file solves the problem. Therefore, we are generating two separate xml and xsd files.
// xsd for the structure and xml for the data.

if (chkSchema.Checked == true)
{
    // Build xsd file path (xsdtarget)
    string xsdtargetFile = "";
    xsdtargetFile = Path.Combine(this.txtTargetPath.Text, _servicedDataSet.DataSetName + ".xsd");

    // Publish the dataset as XML
    _servicedDataSet.WriteXml(targetFile, XmlWriteMode.IgnoreSchema);

    // Creating the xsd file from the dataset.
    string schema = _servicedDataSet.GetXmlSchema();

    // Encoding utf-16 is not compatible with Excel. Changing utf-16 to utf-8 sorts the problem
    string result = schema.Replace("utf-16", "utf-8");
    System.IO.File.WriteAllText(xsdtargetFile, result);
}