第3行第1行的错误:xmlParsePI:没有目标名称

时间:2018-06-04 00:35:54

标签: php html xml

我需要为我的在线商店的cms,产品,图片和类别页面生成动态xml。在这里,我向您展示我使用的3个文件。第一个是文件funciones.php:

city1

文件funciones_cms.php:

<?php
function devolver_url ($v,$i,$tipo=1)
   {
   foreach ($v as $linea)
     {
     $b=explode ("#",$linea);
     if ($b[1]==$i)
       $retorno=$b[2];
     }
  return $retorno;
 }
function devolver_url_productos ($v,$i)
   {
   foreach ($v as $linea)
    {
    $b=explode ("#",$linea); 
    if ($b[1]==$i)
      $retorno=$b[2]."/".$b[4]."-".$b[3].".html";
    }
 return $retorno;
 }
function consultar_bd($consulta)
   {
   $bd="XXXXXXX"; 
   $clave="XXXXXXXXX";
   $host="localhost:3306";
   $conexion = mysql_connect($host, $user, $clave);
   mysql_select_db($bd, $conexion);
   $resultado = mysql_query($consulta, $conexion) or die(mysql_error());
   return $resultado;
   }

function quitar_tildes($cadena)
{
$no_permitidas= array ("á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ù","à ","è","ì","ò","ù","ç","Ç","â","ê","î","ô","û","Â","Ê","ÃŽ","Ô","Û","ü","ö","Ö","ï","ä","«","Ò","Ã","Ä","Ë");
$permitidas= array ("a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E");
$texto = str_replace($no_permitidas, $permitidas ,$cadena);
return $texto;
}?>

最后我需要创建文件cms.xml但它不起作用:

<?php
    include ("funciones.php");
    function poner_url_cms ($v)
       {
       $dominio="https://www.mobiliariocomercialmaniquies.com/";
       $l=array("nada","en","fr","es","de","it","ca");
       foreach ($v as $a)
          {
          $b=explode ("#",$a);
          echo '
                <url>
                <loc>'.$dominio.$l[$b[1]].'/content/'.$b[0].'-'.$b[2].'</loc>
                ';
          for ($i=1;$i<7;$i++)
             {
             if ($i<>$b[1])
                {
                echo '<xhtml:link 
                rel="alternate"
                ';
                echo 'hreflang="'.$l[$i].'"
                ';
                echo 'href="'.$dominio.$l[$i].'/content/'.$b[0].'-'.devolver_url($v,$i,1).'"
                />';
                }
             }            
            echo '</url>
            '; 
          }
       } 
    function generar_sitemap()
       {
       $consulta= "SELECT id_lang, id_cms,link_rewrite FROM ps_cms_lang";
       $resultado = consultar_bd($consulta);
       $filas = mysql_num_rows($resultado);
       $cms=0;
       if ($filas > 0) 
       {
       while ($r= mysql_fetch_assoc($resultado)) 
       {  
          if ( ($r['link_rewrite']<>"") && ($r['id_lang']<7) ) 
             {
               if ($r['id_cms']==$cms)
                   {
                   $v[]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
                   }
               else
                   {
                   if ($cms==0)
                      {
                      unset($v);
                      $cms=$r['id_cms'];
                      $v[0]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
                      }         
                   else
                      {
                      poner_url_cms($v);
                      unset($v);
                      $cms=$r['id_cms'];
                      $v[0]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
                      }
                   }
             }  
          }
       poner_url_cms($v);   
       }
    }
    ?>

我需要为我的在线商店的cms,产品,图片和类别页面生成动态xml。你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

  1. 您的'cms.xml'未被网络服务器解析为PHP
  2. HTTP客户端收到PHP源
  3. PHP源代码无效XML
  4. 客户端中的XML解析器抛出错误
  5. 如果您将文件命名为cms.xml,则Web服务器将不会将其作为PHP执行(至少在没有特殊配置的情况下)。这意味着PHP源将被发送到HTTP客户端。这包括在文件顶部启动PHP源的<?

    XML中的

    <?用于processing instructions(短PI),但它们需要目标名称,如<?xml-stylesheet ...?>