建立空项目,创建脚本XMlsc,挂载到空项目,建立xml文件存储在Assets
using UnityEngine;
using System.Collections;
using System.Xml;//xml解析的命名空间
public class XMLsc : MonoBehaviour {
string fileName = "/book.xml";
string filePath = string.Empty;
void Start () {
Debug.Log (Application.dataPath);//项目中的Assets目录
filePath = Application.dataPath + fileName;
XmlDocument doc = new XmlDocument ();
doc.Load (filePath);//加载xml文件,加载时,将xml内容加载到内存中,
//在内存中生成节点的树状结构
//节点:有元素节点,文本节点,(属性节点)
//元素:标签和标签内容组成元素
//XmlNode是XmlElement的父类
XmlNode rootEle = doc.SelectSingleNode ("root");//获取根节点
XmlElement newElement = doc.CreateElement ("book");//创建名字是book的节点
newElement.InnerText = &