赞
踩
上代码!!!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Xml;
- using System.IO;
- using UnityEngine.UI;
-
- public class TestXml : MonoBehaviour
- {
-
- string pathXML;//xml文件路径
- [SerializeField]
- Text text;
- string xml;
- // Start is called before the first frame update
- void Start()
- {
- pathXML = Application.streamingAssetsPath + "/XML";
- }
-
-
- /// <summary>
- /// 创建xml文件
- /// </summary>
- public void CreatXML()
- {
-
-
- if (!File.Exists(pathXML))
- {
- File.Create(pathXML);
- }
- //创建一个xml的实例
- XmlDocument xmlDoc = new XmlDocument();
-
- //创建最上方一层的节点
- XmlElement parentRoot = xmlDoc.CreateElement("Team");
- parentRoot.SetAttribute("Name", "Dreamer");
-
- //创建下一层节点
- XmlElement student = xmlDoc.CreateElement("Student");
-
- //继续创建下一层节点
- XmlElement name = xmlDoc.CreateElement("Name");
-
- //设置节点中的数值
- name.InnerText = "WFM";
- XmlElement age = xmlDoc.CreateElement("Age");
- age.InnerText = "25";
- XmlElement id = xmlDoc.CreateElement("ID");
- id.InnerText = "19950822";
-
- //xml的保存是根据以下代码顺序按照先后顺序添加的
- student.AppendChild(name);
- student.Appen
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。