using UnityEngine;
using System.Collections;
using System.IO;
using System.Xml;
public class XMLTest : MonoBehaviour
{
void Start()
{
XmlDocument xml = CreateXML();
AddNodeToXML(xml, "123", "this is a xml test !请输入相关信息内容");
AddNodeToXML(xml, "456", "this is a xml test !请输入相关信息内容");
UpdateNodeToXML();
SaveXML(xml);
}
XmlDocument CreateXML()
{
//新建xml对象
XmlDocument xml = new XmlDocument();
//加入声明
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
//加入根元素
xml.AppendChild(xml.CreateElement("Root"));
return xml;
}
void AddNodeToXML(XmlDocument xml, string titleValue, string infoValue)
{
//获取根节点
XmlNode root = xml.SelectSingleNode("Root");
//添加元素
XmlElement element = xml.CreateElement("Node");