hiramyoucan 2013-02-05 07:51 采纳率: 100%
浏览 3371
已采纳

Unity3D 实时解析XML时报错

获取网络时间:

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);
请问如何解决,谢谢!

  • 写回答

2条回答 默认 最新

  • Hiram9846 2013-04-18 10:04
    关注

    还是我自己回答吧:

    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);
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器