0

How to add attribute to data Member?

Current datamember:

 [DataMember(Order = 18, Name = "shippingAddress")]
  public SubscriptionAddressOut ShippingAddress { get; set; }

This is my current output:

            <b:shippingAddress>
                 <b:name>abcd</b:name>
             </b:shippingAddress>

Required output:

     <a:address type="shipping">
                <a:name>abc</a:name>
            </a:address>
Techgeeks1
  • 556
  • 1
  • 4
  • 18
  • Do you just want to add an attribute to an xml element from c# in code? – Stan1k Mar 17 '21 at 10:27
  • If you are using [tag:datacontractserializer] then this serializer does not support XML attributes, see [DataContract XML serialization and XML attributes](https://stackoverflow.com/q/4858798/3744182) and [How can you control .NET DataContract serialization so it uses XML attributes instead of elements?](https://stackoverflow.com/q/591907/3744182). You will need to switch to [`XmlSerializer`](https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer) or implement [`IXmlSerializable`](https://stackoverflow.com/a/280077/3744182). – dbc Mar 17 '21 at 13:11
  • If you are not using [tag:datacontractserializer] then could you please [edit] your question to share a [mcve] showing how you are serializing your object? – dbc Mar 17 '21 at 13:12

0 Answers0