我正在嘗試寫入XML文件。寫入XML文件
我有一個配置列表。
[Serializable]
public class Configuration
{
public decimal X { get; set; }
public decimal Y { get; set; }
}
這是我的財產。
[XmlArray("Configurations")]
[XmlArrayItem("Configuration")]
public List<Configuration> Configurations { get;set; }
來電者是:
this.Configurations = new List<Configuration>()
{
new Configuration() { X = 1, Y = 10 },
new Configuration() { X = 10, Y = 100 },
};
string filename = "test.xml";
TextWriter writer = new StreamWriter(filename);
XmlSerializer serializer = new XmlSerializer(typeof(List<Configuration>));
serializer.Serialize(writer, this.Configurations));
writer.Close();
,輸出是:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Configuration x="1" y="10" />
<Configuration x="10" y="100" />
</ArrayOfConfiguration>
有可以生成此XML文件的方法嗎?
<?xml version="1.0" encoding="utf-8"?>
<Configurations>
<Configuration X="1" Y="10" />
<Configuration X="10" Y="100" />
</Configurations>
有沒有辦法以這種方式生成它們?
是。做手動序列化;-) – Cameron 2012-02-17 22:53:59
我不知道那種方式,會怎麼樣? – 2012-02-17 22:58:27
爲什麼第二個「」沒有這些屬性? –
svick
2012-02-17 22:58:30