using UnityEngine;
using System.Collections;
using System.IO;
using System.Xml;
public class xml : MonoBehaviour {
XmlDocument xmlDoc = new XmlDocument ();
void Start ()
{
XmlDocument xmlDoc = new XmlDocument ();
xmlDoc.Load ("Assets/1.xml");
XmlNode root = xmlDoc.SelectSingleNode ("users");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlNode xn in nodeList)
{
XmlElement xe = (XmlElement)xn;
XmlNodeList subList = xe.ChildNodes;
foreach (XmlNode xmlNode in subList)
{
if ("name".Equals (xmlNode.Name))
{
Debug.Log (xmlNode.InnerText);
}
else if ("email".Equals (xmlNode.Name))
{
Debug.Log (xmlNode.InnerText);
}
}
}
}
}
xml为
<?xml version="1.0" encoding="utf-8"?>
<users>
<user id="1001">
<name>张三</name>
<email>163@163.com</email>
</user>
<user id="1002">
<name>李四</name>
<email>999@qq.com</email>
</user>
</users>