|
-
Apr 12th, 2007, 08:29 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] Serialize a List<T> to XML.
Hi,
I´d like to serialize a List<T> to XML.
Let´s say I have;
Code:
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).
Code:
<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.
-
Apr 12th, 2007, 08:56 AM
#2
Thread Starter
Hyperactive Member
Re: [2.0] Serialize a List<T> to XML.
By adding the, XmlArrayAttribute, I can modify this outter tag.
Code:
[System.Xml.Serialization.XmlArrayAttribute("Properties")]
public List<Person> ReturnMyPersonListCollection
{
get
{
return this.ReturnMyPersonListCollection;
}
}
Found the answer here;
http://msdn2.microsoft.com/en-us/lib...0z(VS.71).aspx
Last edited by Rauland; Apr 12th, 2007 at 09:40 AM.
Reason: Update
-
Apr 13th, 2007, 04:45 AM
#3
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2.0] Serialize a List<T> to XML.
I couldn´t find it in the first place, as it didn´t appear in the intelisense drop down,
Why would this happen?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|