views:

357

answers:

1

I have a dataset which I am populating via an Oracle SQL query:

SELECT col_id, col_desc
FROM table_data;

Then I generate the dataset, via the function

Dim ds as New DataSet
OracleDataAdapter.Fill(ds)

Now, when I get the XML of the generated dataset via:

Dim strXML as String 
strXML = ds.GetXML()

When I read/display the string, it is showing as follows:

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

What I want is that the resulting string should rather display as follows:

<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 would I be able to accomplish this?

Would it be easy if say, I would read the rows from the table in the dataset and construct the string?

Your inputs would be highly appreciated. Thanks.

A: 

UPDATED

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


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

Alfred Myers
Would appreciate if you could show some example. Thanks.
Angelo
There is a an example on the link I provided. Have you taken a look at it?
Alfred Myers
Added sample code ilustrating how to do it with DataColumn.ColumnMapping
Alfred Myers