是否有可能让DataSet.GetXML()将数据放入属性而不是元素?

时间:2009-08-20 00:04:18

标签: xml vb.net ado.net dataset

我有一个数据集,我通过Oracle SQL查询填充:

SELECT col_id, col_desc
FROM table_data;

然后我通过函数

生成数据集
Dim ds as New DataSet
OracleDataAdapter.Fill(ds)

现在,当我通过以下方式获取生成的数据集的XML时

Dim strXML as String 
strXML = ds.GetXML()

当我读取/显示字符串时,它显示如下:

<NewDataSet>
  <Table>
    <COL_ID>ABC001</COL_ID>
    <COL_DESC>Angelo</COL_DESC>
  </Table>
  <Table>
    <COL_ID>ZFE851</COL_ID>
    <COL_DESC>John</COL_DESC>
  </Table>
  <Table>
    <COL_ID>XYU123</COL_ID>
    <COL_DESC>Mary</COL_DESC>
  </Table>
  <Table>
    <COL_ID>MLP874</COL_ID>
    <COL_DESC>James</COL_DESC>
  </Table>
</NewDataSet>

我想要的是结果字符串应该显示如下:

<NewDataSet>
  <Table COL_ID="ABC001" COL_DESC="Angelo"></Table>
  <Table COL_ID="ZFE851" COL_DESC="John"></Table>
  <Table COL_ID="XYU123" COL_DESC="Mary"></Table>
  <Table COL_ID="MLP874" COL_DESC="James"></Table>
</NewDataSet>

我怎样才能做到这一点?

如果说,我会从数据集中的表中读取行并构造字符串吗?

1 个答案:

答案 0 :(得分:1)

已更新

在获取XML之前将DataColumn.MappingType设置为MappingType.Attribute:


    Dim column As DataColumn
    For Each column In ds.Tables.Item(0).Columns
        column.ColumnMapping = MappingType.Attribute
    Next
    ds.GetXml()