Get rid of root element when serializing array

后端 未结 2 1893
小鲜肉
小鲜肉 2021-01-19 21:08

Here\'s a code example:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

...

2条回答
  •  [愿得一人]
    2021-01-19 22:01

    That's a malformed XML you want, not possible to obtain it via XmlSerializer, but you can change ArrayOfPersno element name to smothing else:

    example:

    XmlSerializer xs = new XmlSerializer(typeof(Person[]),
                                         new XmlRootAttribute("Persons"));
    

    will give you:

    
    
      
        John
        Smith
      
      ...
    

提交回复
热议问题