XML attribute for serialization

Discussion in 'ASP .Net Web Services' started by Albert Jan, Oct 11, 2004.

  1. Albert Jan

    Albert Jan Guest

    Hi,

    I use XML in a webservice that looks like this:

    <address>
    <addressline>aaaa</addressline>
    <addressline>aaaa</addressline>
    <zip></zip>
    <city></city>
    </address>

    which I want to serilize to objects.

    When <address> does only contain <addressline> tags, I can use an attribute
    like

    [XmlArrayItem (typeof(addresslineType), ElementName = "addressline")]
    virtual public addresslineType[] Address
    {
    get {return address;}
    set{this.address= value;}
    }
    private addresslineType[] address;


    for the adress object.

    But because <address> also contains other elements I don't know what
    attribute to use for correct serialization

    Any help will be appreciated

    Albert Jan
    Albert Jan, Oct 11, 2004
    #1
    1. Advertising

  2. Albert Jan

    Drew Robbins Guest

    You can use the XmlElement attribute...

    [XmlElement("addressline")]
    public addressAddressline[] Address
    { get; set; }

    Albert Jan wrote:
    > Hi,
    >
    > I use XML in a webservice that looks like this:
    >
    > <address>
    > <addressline>aaaa</addressline>
    > <addressline>aaaa</addressline>
    > <zip></zip>
    > <city></city>
    > </address>
    >
    > which I want to serilize to objects.
    >
    > When <address> does only contain <addressline> tags, I can use an attribute
    > like
    >
    > [XmlArrayItem (typeof(addresslineType), ElementName = "addressline")]
    > virtual public addresslineType[] Address
    > {
    > get {return address;}
    > set{this.address= value;}
    > }
    > private addresslineType[] address;
    >
    >
    > for the adress object.
    >
    > But because <address> also contains other elements I don't know what
    > attribute to use for correct serialization
    >
    > Any help will be appreciated
    >
    > Albert Jan
    >
    >
    >
    >
    Drew Robbins, Oct 11, 2004
    #2
    1. Advertising

  3. Albert Jan

    Albert Jan Guest

    Some things can be so easy ;-)

    Thanks!

    Albert Jan

    "Drew Robbins" <"drew at drewby.com"> wrote in message
    news:...
    > You can use the XmlElement attribute...
    >
    > [XmlElement("addressline")]
    > public addressAddressline[] Address
    > { get; set; }
    >
    > Albert Jan wrote:
    > > Hi,
    > >
    > > I use XML in a webservice that looks like this:
    > >
    > > <address>
    > > <addressline>aaaa</addressline>
    > > <addressline>aaaa</addressline>
    > > <zip></zip>
    > > <city></city>
    > > </address>
    > >
    > > which I want to serilize to objects.
    > >
    > > When <address> does only contain <addressline> tags, I can use an

    attribute
    > > like
    > >
    > > [XmlArrayItem (typeof(addresslineType), ElementName = "addressline")]
    > > virtual public addresslineType[] Address
    > > {
    > > get {return address;}
    > > set{this.address= value;}
    > > }
    > > private addresslineType[] address;
    > >
    > >
    > > for the adress object.
    > >
    > > But because <address> also contains other elements I don't know what
    > > attribute to use for correct serialization
    > >
    > > Any help will be appreciated
    > >
    > > Albert Jan
    > >
    > >
    > >
    > >
    Albert Jan, Oct 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,225
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,009
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    764
    Dimitri Ognibene
    Sep 2, 2006
  4. Ramunas Urbonas
    Replies:
    1
    Views:
    381
    Dino Chiesa [Microsoft]
    Jul 27, 2004
  5. MattL

    Serialization across 'like' attribute names

    MattL, Dec 8, 2004, in forum: ASP .Net Web Services
    Replies:
    8
    Views:
    155
    MattL
    Jan 6, 2005
Loading...

Share This Page