最近做了个小抽奖,名单就用xml来生成了

<?xml version="1.0" encoding="utf-8"?>
<names>
    <name id="7">a君</name>
    <name id="9">b君</name>
    <name id="10">c君</name>
<names>
  /*
    # 读取文件
    # xml文档路径
    */
    this.loadXML = function(xmlFile){
        var xmlDoc;  
        var xmlhttp = new window.XMLHttpRequest();  
        xmlhttp.open("GET",xmlFile,false);  
        xmlhttp.send(null);  
        xmlDoc = xmlhttp.responseXML.documentElement;
        return xmlDoc;  
    }

结果chrome下突然报错:cannot read property documentElement of null

一般这个错误是没有根元素造成的,但检查了一下我xml里的确是有根元素的。看下生成的源代码,看到了id的引号变成了中文的引号,看看生成代码

$xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
$xml.="<names>\r\n";
while($row = mysql_fetch_array($res))
{
   $xml.= "<name id='".$row['uid']."'>".$row['cname']."</name>\r\n";
}
 
$xml.= $tmp."</names>"

用的是单引号,但是chrome自己会讲转变为双引号,然后出错。

改一下就完事了。

$xml.= "<name id=\"".$row['uid']."\">".$row['cname']."</name>\r\n";

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2021-09-01
  • 2022-03-08
  • 2021-07-27
  • 2021-06-08
  • 2022-02-03
  • 2021-08-04
相关资源
相似解决方案