【发布时间】:2009-07-11 02:36:27
【问题描述】:
我有以下代码:
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 中通常认为的正常内容。
【问题讨论】:
标签: .net xml xml-serialization