单独解析androidXml

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine.UI;
using System.IO;
using System.Text;
public class AnalyzeXMLAlone : MonoBehaviour {
public GameObject aa;
public string _result;
public string score;

void Start()
{

StartCoroutine(Load());
}
IEnumerator Load()
{
string localPath = Application.streamingAssetsPath + "/AndroidLoad.xml";
WWW www = new WWW(localPath);
while (!www.isDone)
{
Debug.Log("Getting GetXML");
yield return www;
ParseXml(www);

}
}
//解析
public void ParseXml(WWW www)
{
List<XmlNode> xmlNodeList = new List<XmlNode>();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
XmlNodeList nodeList = xmlDoc.SelectSingleNode("Image").ChildNodes;
//遍历每一个节点,拿节点的属性以及节点的内容
foreach (XmlElement xe in nodeList)
{
foreach (XmlElement x1 in xe.ChildNodes)
{

//分割为字符串数组(Split)
string newstr = x1.InnerText;
//Debug.Log("newstr+"+newstr);
string[] arr = newstr.Split('|');
//判断文件是否存在,否则下载--成功读取图片名字
//score += arr[1];
// aa.text = "分数是:" + score;
aa.GetComponent<Text>().text = "分数是:" + arr[1];
xmlNodeList.Add(x1);

}

}
//xmlDoc.Save(filepath);

}
void OnGUI()
{
GUIStyle titleStyle = new GUIStyle();
titleStyle.fontSize = 20;
titleStyle.normal.textColor = new Color(46f / 256f, 163f / 256f, 256f / 256f, 256f / 256f);
GUI.Label(new Rect(400, 10, 500, 200), _result, titleStyle);
}
}

posted @ 2016-06-24 10:19  Fei非非  阅读(259)  评论(0编辑  收藏  举报