Test Foro de elhacker.net SMF 2.1

Programación => Desarrollo Web => PHP => Mensaje iniciado por: Zieg Uchiha en 2 Abril 2009, 21:33 PM

Título: Abrir un XML
Publicado por: Zieg Uchiha en 2 Abril 2009, 21:33 PM
HOla e buscado en muchos foros y no encontrado respuesta.

quiero abrir un XML y el simplexml_load_file no me va.

este es el archivo con el que estoy haciendo pruebas

Código (xml) [Seleccionar]


<?xml version='1.1' standalone='yes'?>
<movies>
<movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
</movie>
</movies>


y pruebo con este script para ver que pasa

Código (php) [Seleccionar]

<?php
// El fichero test.xml contiene un documento XML con el elemento raiz
// y almenos un elemento /[root]/title.

if (file_exists('ejemplo.xml')) {
    
$xml simplexml_load_file('ejemplo.xml');

    
var_dump($xml);
} else {
    exit(
'Error al abrir test.xml.');
}
?>



al ejecutar esto me da estos errores.

Citar

Warning: simplexml_load_file() [function.simplexml-load-file]: ejemplo.xml:2: parser error : XML declaration allowed only at the start of the document in C:\AppServ\www\experimentos2.php on line 6

Warning: simplexml_load_file() [function.simplexml-load-file]: <?xml version='1.1' standalone='yes'?> in C:\AppServ\www\experimentos2.php on line 6

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\AppServ\www\experimentos2.php on line 6
bool(false)

espero puedan ayudarme.

Thx

saludos.
Título: Re: Abrir un XML
Publicado por: HardieVon en 2 Abril 2009, 21:55 PM
esta mal la cabecera.

ponle esto.
Código (xml) [Seleccionar]

<?xml version="1.0"?>


en vez de lo que tiene,
Título: Re: Abrir un XML
Publicado por: Zieg Uchiha en 2 Abril 2009, 22:02 PM
No pasa nada :( es lo mismo.
Título: Re: Abrir un XML
Publicado por: HardieVon en 2 Abril 2009, 22:17 PM
como crees si yo ya lo probe
Código (xml) [Seleccionar]

<?xml version="1.0"?>

<movies>

<movie>

  <title>PHP: Behind the Parser</title>

  <characters>

   <character>

    <name>Ms. Coder</name>

    <actor>Onlivia Actora</actor>

   </character>

   <character>

    <name>Mr. Coder</name>

    <actor>El Act&#38;#211;r</actor>

   </character>

  </characters>

  <plot>

   So, this language. It's like, a programming language. Or is it a

   scripting language? All is revealed in this thrilling horror spoof

   of a documentary.

  </plot>

  <rating type="thumbs">7</rating>

  <rating type="stars">5</rating>

</movie>

</movies>
Título: Re: Abrir un XML
Publicado por: Syphroot en 3 Abril 2009, 05:11 AM
<?xml version='1.1' standalone='yes'?>
prueba a poner los valores entre comillas dobles "1.0" y "yes"
Título: Re: Abrir un XML
Publicado por: Zieg Uchiha en 3 Abril 2009, 16:53 PM
despues de muchos intentos me funciono, es raro por que a veces me tira error diciendome que no puede abrirlo o que no lo reconoce, pero en fin.

Gracias.