xml格式如下:
<item>
<connect server="http://192.168.0.101/api"/>
</item>
解析XML
//解析xml
void parseXml()
{
//也可以前面加上@,区别就是有@的话,双引号里面的内容不转义,比如" \" "
string filePath = Application.streamingAssetsPath + @"/config.xml";
if (!File.Exists(filePath))
{
Debug.LogError("配置文件不存在");
return;
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNodeList node = xmlDoc.SelectSingleNode("item").ChildNodes;
//遍历节点
foreach (XmlElement ele in node)
{
if (ele.Name == "connect")
{
remoteServer = ele.Attributes["server"].Value;
Debug.Log(remoteServer);
}
}
}