字符串不能解析为XML


String could not be parsed as XML php android webservice Error

没有将url值从PHP传递到XML转换

警告:SimpleXMLElement::__construct(): Entity:第141行:解析器错误:EntityRef:期望';'在/home/u395985035/public_html/ddd/ddd.php第34行

警告:SimpleXMLElement::__construct(): http://teko.gogo.com/gtw_c?tem_id=844&erw_id=44545在/home/u395985035/public_html/ddd/ddd.php第34行

警告:SimpleXMLElement::__construct(): ^ in/home/u395985035/public_html/ddd/ddd.php第34行

致命错误:未捕获的异常' exception '带有消息'String could '在/home/u395985035/public_html/ddd/ddd.php栈跟踪:#0/home/u395985035/public_html/ddd/ddd.php(34)SimpleXMLElement -> __construct (t ' ' n ' ' t

    <?php
  include("config.php"); 
    $sql = "SELECT * FROM table1";
    $q   = mysqli_query($conn,$sql) or die(mysql_error());
    $xml = "<demo1>'n't't";
    while($r = mysqli_fetch_array($q))   {
      $xml .= "<t_view>'n't";
      $xml .= "<l1>".$r['id']."</l1>'n't't";  
      $xml .= "<l2>".$r['link1']."</l2>'n't't";
      $xml .= "</t_view>'n't";  
    }
       $xml .= "</demo1>'n't't";
    $sxe = new SimpleXMLElement($xml);
    $sxe->asXML("ddd.xml");
 /* I am parsing url link with parameters in $r['link1'] */
?>

好的,不要编码你的url只是尝试这个,我已经测试过了,它是工作的

while($r = mysqli_fetch_array($q))   {
      $xml .= "<t_view>'n't";
      $xml .= "<l1>".$r['id']."</l1>'n't't";  
      $xml .= "<l2>".preg_replace('#&(?=[a-z_0-9]+=)#', '&amp;', $r['link1'])."</l2>'n't't";
      $xml .= "</t_view>'n't";  
    }