views:

118

answers:

1

How would I represent something like this

<product>
   <sku>12452</sku>
   <attribute name="details">good stuff</attribute>
   <attribute name="qty">5</attribute>
</product>

for use in my WCF service? Not sure how to define the multiple attributes whose only difference is the "name".

I need this properly setup as a DataMember so xml gets deserialized into it.

sku would be something like:

[DataMember(Name = "sku")]
public string sku;

What would I use for both of the attributes?

+2  A: 

You won't be able to do that using DataContracts, since the DataContract serializer doesn't support XML attributes (only elements). If you really need to generate messages with that schema, you'll have to use XmlSerializer instead.

tomasr
If DataContracts are newer, why wouldn't they support attrributes? Are they deprecated?
Chris Klepeis
@Chris: the DataContractSerializer doesn't support attributes on XML nodes for performance reasons. Not supporting those makes the DCS around 10-15% faster than the XmlSerializer on the same document.
marc_s