Setting attributes XML

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

about XML 18
Dataset with XML 3
Read XML File 4
XML attributes or node ? 3
Create summary from xml 2
XML Deserialization Attribute vs. Element 2
Xml root element attributes 2
Applying schema and default attributes 3

Top