views:

162

answers:

1

The heading pretty much explains what I would like to achieve, but here is an example to elaborate further:

Given the following table:

CREATE TABLE [CustSchema].[TestTable](
    [Desc] [varchar](50) NOT NULL
) ON [PRIMARY]

When I load this table into a DataTable, and then spit it out again using DataSet.WriteXml(), I get the following output:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <TestTable>
    <Desc>XROW1</Desc>
  </TestTable>
  <TestTable>
    <Desc>XROW2</Desc>
  </TestTable>
</NewDataSet>

Whereas, I would like to preserve the table's schema - ie, get this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <CustSchema.TestTable>
    <Desc>XROW1</Desc>
  </CustSchema.TestTable>
  <CustSchema.TestTable>
    <Desc>XROW2</Desc>
  </CustSchema.TestTable>
</NewDataSet>

Can anyone point me in the right direction? TIA.

A: 
System.Data.DataSet ds;
ds.WriteXml(*some stream*, System.Data.XmlWriteMode.WriteSchema);

System.Data.DataSet.WriteXml
XmlWriteMode Enumeration

Austin Salonen
Unfortunately that writes the XML schema, not the table schema - ie:<?xml version="1.0" standalone="yes"?><NewDataSet> <xs:schema ...> ... </xs:schema> <Tbl1> <Desc>XROW1</Desc> </Tbl1> <Tbl1> <Desc>XROW2</Desc> </Tbl1></NewDataSet>
KevinT