views:

17

answers:

1

Hello all,

I'm trying to use Dataset.WriteXml() function in VB.Net to generate an XML file with Pretty-Print Layout (I think this is how it's named) like the example below (Listing 1):

<MainRoot>
   <Table1>
      <Col1>Value1</Col1>
      <Col2>Value2</Col2>
      <Col3></Col3>
      <Col4>Value4</Col4>
   </Table1>
   <Table2>
      <Col1></Col1>
      <Col2></Col2>
      <Col3></Col3>
      <Col4>Value4</Col4>
   </Table2>
</MainRoot>

Now, the problem is that I'm not getting the file with this format, and it's formatted like this (Listing 2):

<MainRoot>
   <Table1
      Col1="Value1"
      Col2="Value2"
      Col3=""
      Col4="Value4" />
   <Table2
      Col1=""
      Col2=""
      Col3=""
      Col4="Value4" />
</MainRoot>

I tried to use XMLWriterSettings and played around with the properties there with no use.....

My Question: Is there anyway to format the XML stream that is generated from the dataset to be formatted as in Listing 1 I shown above???

A: 

Looks like you solved this problem, but for others, you can configure this kind of thing by changing the ColumnMapping property on your columns:

foreach (DataColumn dc in dt.Columns)
{
  dc.ColumnMapping = MappingType.Attribute;
}
Martin Owen