我是 xml 新手,我正在尝试以以下格式保存一些内容:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<brickTable>
<value>23039</value>
<Tile>Brick</Tile>
<X>18400</X>
<Y>64</Y>
<items>
<itemType>Type1</itemType>
</items>
<items>
<itemType>Type5</itemType>
</items>
</brickTable>
</NewDataSet>
如图所示,我希望成为砖桌的一部分,但我不知道该怎么做。我目前有上面的格式,但没有任何部分。
我目前的代码如下:
System.Data.DataSet ds;
ds = new DataSet();
System.Data.DataTable tile_table;
tile_table = new DataTable("tiles");
//add an auto increment column
DataColumn column1 = new DataColumn();
column1.DataType = System.Type.GetType("System.Int32");
column1.ColumnName = "value";
column1.AutoIncrement = true;
tile_table.Columns.Add(column1);
//add index key
DataColumn[] keys = new DataColumn[1];
keys[0] = column1;
tile_table.PrimaryKey = keys;
//tilemap data columns
DataColumn TileType = new DataColumn();
TileType.DataType = System.Type.GetType("System.String");
TileType.ColumnName = "Tile";
tile_table.Columns.Add(TileType);
DataColumn X = new DataColumn();
X.DataType = System.Type.GetType("System.Int32");
X.ColumnName = "X";
tile_table.Columns.Add(X);
DataColumn Y = new DataColumn();
Y.DataType = System.Type.GetType("System.Int32");
Y.ColumnName = "Y";
tile_table.Columns.Add(Y);
DataRow row = tile_table.NewRow();
row["value"] = count;
row["Tile"] = tileListRear[index].tileType.ToString();
row["X"] = tileListRear[index].X;
row["Y"] = tileListRear[index].Y;
row["Layer"] = NewMapEditor.Layer.Rear.ToString();
tile_table.Rows.Add(row);
//save xml file
ds.Tables.Add(infoTable);
ds.Tables.Add(tile_table);
ds.WriteXml(g_filename);
谢谢你的帮助!