XNA - xml該是怎樣的格式?
我想要載入xml存成自己的物件,
例如我的物件是
1: public class MyData {
2: public Vector2 Origin = Vector2.Zero;
3: public Color Color = Color.White;
4: public Rectangle? Source = null;
5: public TimeSpan StayTime = TimeSpan.Zero;
6: }
雖然我知道要寫Reader和Writer,但是我不知道XML該如何編輯阿?
我想到了一個簡單的解決方案,就是在程式裡產生好物件後,自己存一份看看!
使用下列程式碼:
1: MyData testData = new MyData();
2:
3: XmlWriterSettings settings = new XmlWriterSettings();
4: settings.Indent = true;
5: XmlWriter writer = XmlWriter.Create("test.xml", settings);
6: IntermediateSerializer.Serialize(writer, testData, null);
7: writer.Close();
會將物件存成xml檔,如此就可以知道xml內容該如何編寫了!