string fileName = "/Demo.xml";
string path ="";
void Start () {
path= Application.streamingAssetsPath + fileName;
LoadFile (path);
}
void LoadFile(string _path){
XmlDocument doc = new XmlDocument ();
doc.Load (_path);
//Debug.Log(doc.Name);
XmlNode root = doc.SelectSingleNode ("root");
Debug.Log (root.InnerText);
foreach (XmlElement item in root) {
if (item.Name == "level2") {
item.InnerText="3";
test.Add (item.InnerText);
}
}
doc.Save (path);
}
root为xml文件的根节点,从根节点开始以此查找。
1、Element是一个小范围的定义,必须含有完整信息的节点才能叫做元素。
2、Node是基本对象,Attribute、Element、Text等都是Node的子对象。
一个元素一定是一个节点,而一个节点不一定是元素。