将sql数据导出为xml

本文关键字:xml sql 数据 | 更新日期: 2023-09-27 18:28:30

我将数据从sql导出到xml,但我对xml的格式有问题。我现在有这个输出:

<?xml version="1.0" standalone="yes"?>
    <ITEMS>
      <ITEM>
        <CATALOG_NUMBER>1047</CATALOG_NUMBER>
        <ITEM_NAME>Adrian3 Navy Grey Red </ITEM_NAME>
        <UNIT>KUS  </UNIT>
        <COUNTRY>CZ  </COUNTRY>
        <CURRENCY>CZK</CURRENCY>
        <PRICE_VAT>797.00</PRICE_VAT>
        <PRICE_VAT1>21.0</PRICE_VAT1>
        <NOTE>Sportovní bota v barvě...
        </NOTE>
      </ITEM>
      <ITEM>
        <CATALOG_NUMBER>106</CATALOG_NUMBER>
        <ITEM_NAME>Betty Hot pink</ITEM_NAME>
        <UNIT>KUS  </UNIT>
        <COUNTRY>CZ  </COUNTRY>
        <CURRENCY>CZK</CURRENCY>
        <PRICE_VAT>797.00</PRICE_VAT>
        <PRICE_VAT1>21.0</PRICE_VAT1>
        <NOTE>Krásná a jednoducháým...
        </NOTE>
      </ITEM>
      <ITEM_GROUPS>
        <GROUP>00010000000000000000</GROUP>
        <GROUP_NAME>Pediped</GROUP_NAME>
      </ITEM_GROUPS>
      <ITEM_GROUPS>
        <GROUP>00010001000000000000</GROUP>
        <GROUP_NAME>Original</GROUP_NAME>
      </ITEM_GROUPS>
      <ITEM_GROUPS>
        <GROUP>00010002000000000000</GROUP>
        <GROUP_NAME>Gripngo</GROUP_NAME>
      </ITEM_GROUPS>
    </ITEMS>

但我需要这种格式:

<ITEMS>
  <ITEM>
    <CATALOG_NUMBER>1047</CATALOG_NUMBER>
    <ITEM_NAME>Adrian3 Navy Grey Red </ITEM_NAME>
    <UNIT>KUS  </UNIT>
    <COUNTRY>CZ  </COUNTRY>
    <CURRENCY>CZK</CURRENCY>
    <PRICE_VAT>797.00</PRICE_VAT>
    <PRICE_VAT1>21.0</PRICE_VAT1>
    <NOTE>Sportovní bota v barvě...
    </NOTE>
  </ITEM>
  <ITEM>
    <CATALOG_NUMBER>106</CATALOG_NUMBER>
    <ITEM_NAME>Betty Hot pink</ITEM_NAME>
    <UNIT>KUS  </UNIT>
    <COUNTRY>CZ  </COUNTRY>
    <CURRENCY>CZK</CURRENCY>
    <PRICE_VAT>797.00</PRICE_VAT>
    <PRICE_VAT1>21.0</PRICE_VAT1>
    <NOTE>Krásná a jednoducháým...
    </NOTE>
  </ITEM>
  <ITEM_GROUPS>
    <GROUP>00010000000000000000</GROUP>
    <GROUP_NAME>Pediped</GROUP_NAME>
    <GROUP>00010001000000000000</GROUP>
    <GROUP_NAME>Original</GROUP_NAME> 
    <GROUP>00010002000000000000</GROUP>
    <GROUP_NAME>Gripngo</GROUP_NAME>
  </ITEM_GROUPS>
</ITEMS>

我希望在xml的第二部分中,我希望只有一次和。我没有xml。。。。

这是我的代码:

SqlConnection con = new SqlConnection("Data Source=****");
string strSQL = "select top 3 D.KOD_ZBOZI AS CATALOG_NUMBER.....";
string strSQL2 = "select [OBCH_......";
SqlDataAdapter dt = new SqlDataAdapter(strSQL, con);
SqlDataAdapter dt2 = new SqlDataAdapter(strSQL2, con);
DataSet ds = new DataSet("ITEMS");
dt.Fill(ds, "ITEM");
dt2.Fill(ds, "ITEM_GROUPS");
ds.WriteXml(("C:''Users''Lukas''Desktop''NOHEL.xml"));

有什么想法吗?

将sql数据导出为xml

您可以尝试作为:

DataSet ds = new DataSet("ITEMS");

你这样做了吗:
DataSetName属性