獲取網絡時間:
IEnumerator GetTime()
{
WWW www = new WWW(timeURL);
while (!www.isDone)
{
yield return www;
Debug.Log("Doneeeeeeeeeeeeee" + www.text);
ParseXml(www);
}
}`
後得到:`
<?xml version="1.0" encoding="GB2312" ?>
- <ntsc>
- <time>
<year>2011</year>
<month>7</month>
<day>10</day>
<Weekday />
<hour>19</hour>
<minite>45</minite>
<second>37</second>
<Millisecond />
</time>
</ntsc>`
然後解析時報錯:
public void ParseXml(WWW www)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(www.text);
XmlElement root = xmlDoc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/ntsc/time");
foreach (XmlElement xe in nodeList)
{
foreach (XmlElement x1 in xe.ChildNodes)
{
if (x1.Name == "year")
{
Debug.LogError("x1.InnerText" + x1.InnerText);
}
}
}
}
報錯語句:xmlDoc.Load(www.text);
請問如何解決,謝謝!
還是我自己回答吧:
public void ParseXml(WWW www)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
XmlElement root = xmlDoc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/ntsc/time");
foreach (XmlElement xe in nodeList)
{
foreach (XmlElement x1 in xe.ChildNodes)
{
if (x1.Name == "year")
Debug.Log("Current year: " + x1.InnerText);
if (x1.Name == "month")
Debug.Log("Current month: " + x1.InnerText);
if (x1.Name == "day")
Debug.Log("Current day: " + x1.InnerText);
if (x1.Name == "hour")
Debug.Log("Current hour: " + x1.InnerText);
if (x1.Name == "minite")
Debug.Log("Current minite: " + x1.InnerText);
if (x1.Name == "second")
Debug.Log("Current second: " + x1.InnerText);
}
}
}