Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Serialize a List<T> to XML.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Resolved [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.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    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
  •  



Click Here to Expand Forum to Full Width