1

我将数据从 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"));

请问有什么想法吗?

4

2 回答 2

3

您可以尝试:

DataSet ds = new DataSet("ITEMS");
于 2013-08-22T06:29:15.803 回答
1

你这样做了吗:
DataSetName 属性

于 2013-08-22T06:24:13.423 回答