Foros del Web » Programando para Internet » PHP »

Imprimir mensaje cuando no hay XML

Estas en el tema de Imprimir mensaje cuando no hay XML en el foro de PHP en Foros del Web. Buenos días amigos, Tengo un problema. Tengo un codigo que me muestra datos de un archivo XML, pero necesito colocar en el codigo que si ...
  #1 (permalink)  
Antiguo 31/05/2012, 07:19
 
Fecha de Ingreso: enero-2012
Mensajes: 109
Antigüedad: 12 años, 3 meses
Puntos: 0
Imprimir mensaje cuando no hay XML

Buenos días amigos,

Tengo un problema. Tengo un codigo que me muestra datos de un archivo XML, pero necesito colocar en el codigo que si el archivo no existe me imprima que NO HAY ARCHIVO DISPONIBLE.

El codigo es:

Código:
<?php
$url = "C:\TelnetWS3\GBSC_ACA.xml";
$contenido_xml = "";
if($d = fopen($url, "r")){
 while ($aux= fgets($d, 1024)){
    $contenido_xml .= $aux;
  }
	  fclose($d);
	}else{
	  echo "No se pudo abrir el XML";
	}
	$xml =simplexml_load_string ($contenido_xml);  
?>

</h1>
  
    <div align="center">

      <table cellspacing="0" cellpadding="0" width="100%" class="tabla" action='' id="tab">
        <tr>
          <th width="2%"></th>
          <th width="5%"></th>
          <th width="15%"></th>
          <th width="25%"></th>
          <th width="8%"></th>
          <th width="7%"></th>
          <th width="5%"></th>
          <th width="13%"></th>
          <th width="8%"></th>
          <th width="10%"></th>
		  
		 
        </tr>
		
        <?php
	
for($i=(count($xml->Alarma)-1); $i>=0; $i--){
		$j=$xml->Alarma[$i]->Severidad;
		if ($j==Critical)	
		
        echo '<tr><td width="2%" id="pru"> </td><td width="5%">'.$xml->Alarma[$i]->Severidad.'</td><td width="15%">'.$xml->Alarma[$i]->Nombre.'</td><td width="25%">'.$xml->Alarma[$i]->Info.'</td><td width="8%">'.$xml->Alarma[$i]->Serial.'</td><td width="7%">'.$xml->Alarma[$i]->ID.'</td><td width="5%">'.$xml->Alarma[$i]->Tipo_A.'</td><td width="13%">'.$xml->Alarma[$i]->Fecha.'</td><td width="8%">'.$xml->Alarma[$i]->Tipo_E.'</td><td width="10%">'.$xml->Alarma[$i]->Nodo_N.'</td></tr>';
		else if ($j==Minor)	
       echo '<tr><td width="2%" id="pru2"> </td><td width="5%">'.$xml->Alarma[$i]->Severidad.'</td><td width="15%">'.$xml->Alarma[$i]->Nombre.'</td> <td width="25%">'.$xml->Alarma[$i]->Info.'</td><td width="8%">'.$xml->Alarma[$i]->Serial.'</td><td width="7%">'.$xml->Alarma[$i]->ID.'</td><td width="5%">'.$xml->Alarma[$i]->Tipo_A.'</td><td width="13%">'.$xml->Alarma[$i]->Fecha.'</td><td width="8%">'.$xml->Alarma[$i]->Tipo_E.'</td><td width="10%">'.$xml->Alarma[$i]->Nodo_N.'</td></tr>';
		else if ($j==Major)	
       echo '<tr><td width="2%" id="pru3"> </td><td width="5%">'.$xml->Alarma[$i]->Severidad.'</td><td width="15%">'.$xml->Alarma[$i]->Nombre.'</td><td width="25%">'.$xml->Alarma[$i]->Info.'</td><td width="8%">'.$xml->Alarma[$i]->Serial.'</td><td width="7%">'.$xml->Alarma[$i]->ID.'</td><td width="5%">'.$xml->Alarma[$i]->Tipo_A.'</td><td width="13%">'.$xml->Alarma[$i]->Fecha.'</td><td width="8%">'.$xml->Alarma[$i]->Tipo_E.'</td><td width="10%">'.$xml->Alarma[$i]->Nodo_N.'</td></tr>';
		else if ($j==Warning)	
       echo '<tr><td width="2%" id="pru1"> </td><td width="5%">'.$xml->Alarma[$i]->Severidad.'</td><td width="15%">'.$xml->Alarma[$i]->Nombre.'</td><td width="25%">'.$xml->Alarma[$i]->Info.'</td><td width="8%">'.$xml->Alarma[$i]->Serial.'</td><td width="7%">'.$xml->Alarma[$i]->ID.'</td><td width="5%">'.$xml->Alarma[$i]->Tipo_A.'</td><td width="13%">'.$xml->Alarma[$i]->Fecha.'</td><td width="8%">'.$xml->Alarma[$i]->Tipo_E.'</td><td width="10%">'.$xml->Alarma[$i]->Nodo_N.'</td></tr>';
	
		}
		
	?>
Gracias
  #2 (permalink)  
Antiguo 31/05/2012, 07:32
 
Fecha de Ingreso: mayo-2012
Mensajes: 61
Antigüedad: 11 años, 11 meses
Puntos: 23
Respuesta: Imprimir mensaje cuando no hay XML

para eso tienes la funcion file exists

http://php.net/manual/es/function.file-exists.php

Saludos!

Etiquetas: mensaje, tabla, xml
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:35.