Is it possible for DataSet.GetXML () to put data in attributes instead of elements?

I have a dataset that I populate via an Oracle SQL query:

SELECT col_id, col_desc
FROM table_data;

      

Then I create a dataset using the function

Dim ds as New DataSet
OracleDataAdapter.Fill(ds)

      

Now when I get the XML of the generated dataset with:

Dim strXML as String 
strXML = ds.GetXML()

      

When I read / display the line, it looks like this:

<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>

      

I want the resulting string to appear rather like this:

<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>

      

How can I do this?

It would be easy to say, I would read rows from a table in a dataset and plot a row?

+2


source to share


1 answer


UPDATED

Set DataColumn.MappingType to MappingType.Attribute before getting XML:




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


      

+1


source







All Articles