Setting attributes XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Quail

    #1

    Setting attributes XML

    Hi to all,

    I have just started looking at XML.Serializati on 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.Seri alization.XMLAt tribute but it sets the
    attributes as attributes of Person.

    TIA
    Steven.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Setting attributes XML

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Steven Quail" <squail71@yahoo .com> wrote in message
    news:3aabc57a.0 307280028.64774 b6c@posting.goo gle.com...[color=blue]
    > Hi to all,
    >
    > I have just started looking at XML.Serializati on 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.Seri alization.XMLAt tribute but it sets the
    > attributes as attributes of Person.
    >
    > TIA
    > Steven.[/color]


    Comment

    Working...