Roger Hill
Roger Hill

Reputation: 4099

Xml serialization as elements with properties

I generally use the DataSet.GetXml() method to serialize datasets, and I came across a problem: Is there an easy way to serialize a dataset object using properties rather than elements? For example, the GetXml() method might generate this from a data set:

<foo>
<height>bleem</height>
<color>yurple</color>
</foo>

but, I would like to see something like:

<foo height="bleem" color="yurple" />

I realize there are constraints on the property oriented approach, but I am using database data, so uniqueness shouldn't be an issue. I have been digging around SO, but I cannot find anything covering this. Any XML experts out there have any ideas?

Upvotes: 1

Views: 134

Answers (1)

gowansg
gowansg

Reputation: 795

I'm no XML expert--I just play one on TV.

I would use the DataColumn.ColumnMapping Property to determine how your columns are mapped. For all the columns you want mapped as XML attributes, set their ColumnMapping equal to MappingType.Attribute.

Upvotes: 1

Related Questions