首先吧需要读取的文件放到该目录下。(我这里读取的是名为item的文件),注意字母不要打错。
这里是item里面的内容
<item>
<item1>
<id>1</id>
<name>china</name>
<year>2016</year>
</item1>
<item2>
<id>2</id>
<name>usa</name>
<year>2017</year>
</item2>
</item>
接着进行读取XML
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.IO;
public class XMLSlote : MonoBehaviour
{
void Start()
{
parseXml();
}
//解析xml
void parseXml()
{
//也可以前面加上@,区别就是有@的话,双引号里面的内容不转义,比如" \" "
//string filePath = Application.dataPath+@"/Resources/item.xml";
string filePath =