PDA

Click to See Complete Forum and Search --> : [RESOLVED] [2.0] Serialize a List<T> to XML.


Rauland
Apr 12th, 2007, 08:29 AM
Hi,

Iīd like to serialize a List<T> to XML.

Letīs say I have;

Class Person
{
,....
}

And another Class;

Class People
{
Private People()
{
}

Public void CreatePerson()
{
Person pr = new Person();
this.myPersonList.Add(pr);
}

List<Person> myPersonList = new List<Person>();

public List<Person> ReturnMyPersonListCollection
{
get
{
return myPersonList;
}
}
}

Okay, If I were to serialize this, I would get sth similiar to this;
(Asume that I have added these attributes,

[System.Xml.Serialization.XmlAttribute("")]

to the public properties of the Person Class).

<ReturnMyPersonListCollection>
<Person>,.....................</Person>
<Person>,.....................</Person>
<Person>,.....................</Person>
<ReturnMyPersonListCollection>


The problem is the outter tag ,<ReturnMyPersonListCollection>,

Iīd like to be able to change this tag to what ever Iīd like it to be,..
Thanks.

Rauland
Apr 12th, 2007, 08:56 AM
By adding the, XmlArrayAttribute, I can modify this outter tag.

[System.Xml.Serialization.XmlArrayAttribute("Properties")]
public List<Person> ReturnMyPersonListCollection
{
get
{
return this.ReturnMyPersonListCollection;
}
}

Found the answer here;
http://msdn2.microsoft.com/en-us/library/2baksw0z(VS.71).aspx

Rauland
Apr 13th, 2007, 04:45 AM
I couldnīt find it in the first place, as it didnīt appear in the intelisense drop down,
Why would this happen?