創建及添加XML檔案:
string localPath = Application.streamingAssetsPath + "/" + "SchoolReport.xml";
if (!File.Exists(localPath))
{
XmlDocument xml = new XmlDocument();
//想要添加XML檔案的話將這行代碼替換為 xml.Load(localPath);
XmlDeclaration xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", "");
//創建根節點
XmlElement root = xml.CreateElement("xml");
//創建子節點
XmlElement info = xml.CreateElement("scoreinfo");
XmlElement info2 = xml.CreateElement("name");
XmlElement info3 = xml.CreateElement("score");
//給子節點添加屬性
//info.SetAttribute("id", "1");
//給子節點寫入資料
info2.InnerText = "aaa";
info3.InnerText = "100";
//按順序創建節點
root.AppendChild(info);
info.AppendChild(info2);
info.AppendChild(info3);
xml.AppendChild(root);
//保存
xml.Save(localPath);
Debug.Log("創建XML成功!");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/398779.html
標籤:其他
下一篇:Django案例:顯示圖書資訊
