开发者

Getting xml from a dataset

开发者 https://www.devze.com 2022-12-08 02:57 出处:网络
I have a DataSet which has one table loaded with data. When i write out the dataset to xml using the GetXml method of the dataset, i get all the columns in that data table as elements in the xml file

I have a DataSet which has one table loaded with data.

When i write out the dataset to xml using the GetXml method of the dataset, i get all the columns in that data table as elements in the xml file.

How do i get the resulting xml with the column values as attributes instead of elements?

开发者_StackOverflow社区

The article here trails off without a proper answer

I am using .NET Framework 2.0


Before writing the XML, do something like

foreach (DataColumn column in aDataSet.Tables[0].Columns)
{
    column.ColumnMapping = MappingType.Attribute;
}

Although I'll admit I didn't test this. You still may get a DiffGram structured file.


 

foreach(DataColumn dc in dsHR.Tables[0].Columns)
    dc.ColumnMapping = MappingType.Attribute;

Quite simple :)

0

精彩评论

暂无评论...
验证码 换一张
取 消