Setting attributes XML

  • Thread starter Thread starter Steven Quail
  • Start date Start date
S

Steven Quail

Hi to all,

I have just started looking at XML.Serialization classes and would
like to know how I set an attribute for an XML element.

For example, I want my XML doc to look like the following:

<Person>
<Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Name>
<Address>
<Number>127</Number>
<Street Name = "Church", Area = "Arlington" />
</Address>
</Person>

What I am interested in setting are the attributes
<Street Name = "Church", Area = "Arlington" />

I tried using System.XML.Serialization.XMLAttribute but it sets the
attributes as attributes of Person.

TIA
Steven.
 
Steven,

In this case, I create a Street object which will expose the Name and
Area properties. Then, on the Street object, apply the XmlAttribute to the
Name and Area properties. Once that is done, have the Street property
expose an instance of the Street class you created.

Hope this helps.
 
Back
Top