XML serialisation

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

    #1

    XML serialisation

    Hi,

    I have a collection of user defined types called
    EmployeeCollect ion which inherits from CollectionBase.
    EmployeeCollect ion is a collection of Employee objects.
    When i serialise the collection, the serialized collection
    looks like:
    <ArrayOfEmploye e>
    <Employee>
    .....
    </Employee>
    </ArrayOfEmployee >

    I tried specifying the XMLRootAttribut e for the collection
    class, but that gives an error reflecting
    EmployeeCollect ion.
    Can anyone please let me know how I can specify my own
    element name for the serialised output.

    Thanks.
    M

  • d2d

    #2
    Re: XML serialisation

    Here is what you do for your own tag name for the serialized output.
    You could specify your own element name by using "XmlElement " attribute
    of type "XmlElementAttr ibute".

    ex)
    class A {
    private int abc;
    [XmlElement("Gar bage")]
    public in Abc {
    // get and set.
    }
    }

    After serializing the class "A",
    You will get something like
    <A xmlns:xsd=htt.. ...>
    <Garbage>
    (Some Garbage integer value)
    </Garbage>
    </A>

    So instead of "Abc", you get the tag named "Garbage" using XmlElement
    attribute.

    Hope that helped.


    M wrote:[color=blue]
    > Hi,
    >
    > I have a collection of user defined types called
    > EmployeeCollect ion which inherits from CollectionBase.
    > EmployeeCollect ion is a collection of Employee objects.
    > When i serialise the collection, the serialized collection
    > looks like:
    > <ArrayOfEmploye e>
    > <Employee>
    > ....
    > </Employee>
    > </ArrayOfEmployee >
    >
    > I tried specifying the XMLRootAttribut e for the collection
    > class, but that gives an error reflecting
    > EmployeeCollect ion.
    > Can anyone please let me know how I can specify my own
    > element name for the serialised output.
    >
    > Thanks.
    > M
    >[/color]

    Comment

    Working...