I have the following code:
public class Foo {}
static class Program {
[XmlElement("foo")] // Ignored :(
static public List<Foo> MyFoos { get; private set; }
public static void Main() {
MyFoos.Add(new Foo());
MyFoos.Add(new Foo());
XmlSerializer configSerializer =
new XmlSerializer(typeof(List<Foo>), new XmlRootAttribute("foos"));
using (TextWriter w = new StreamWriter("test.xml"))
{
s.Serialize(w, MyFoos);
}
}
}
生成以下XML文件:
<?xml version="1.0" encoding="utf-8"?>
<foos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Foo />
<Foo />
</foos>
我真正希望的是将
Foo
元素标记为foo
,而不是...我意识到这主要是表面上的,但它符合XML中通常被认为是正常的。