Here\'s a code example:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
...
IMO you should use a top-level object, I.e.
[XmlRoot("whatever")]
public class Foo {
[XmlElement("Person")]
public List<Person> People {get;set;}
}
Which should serialize as a "whatever" element with multiple "Person" sub-elements.
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:
<?xml version="1.0"?>
<Persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Person>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Person>
...