pedrodbsa
pedrodbsa

Reputation: 1431

Class Fields to XML Element and attribute

I have the following class that I want to serialize to an XML file

public class HDLCParameters
{
    [XmlElement("ClientMACAddress")]
    public string ClientMACAddress { get; set; }
}

this is serialized like this:

 <HDLCParameters>
     <ClientMACAddress>0x10</ClientMACAddress>
 </HDLCParameters>

but i need it like this:

<HDLCParameters>
     <ClientMACAddress value="0x10" />
</HDLCParameters>

Do i need to create a ClientMACAddress class with a "value" field? isn't there a way to set an element and an attribute with its value?

thanks

Upvotes: 0

Views: 794

Answers (1)

fejesjoco
fejesjoco

Reputation: 11903

Create the ClientMACAddress class, give it a value field, and specify that it's an attribute (XmlAttributeAttribute)

Upvotes: 1

Related Questions