Foros del Web » Programando para Internet » PHP »

XML parse con PHP simplexml_load_file();

Estas en el tema de XML parse con PHP simplexml_load_file(); en el foro de PHP en Foros del Web. Tengo este codigo, queria saber si es valido o que pasa. Termine con este codigo: Código PHP: <?xml version = "1.0"  encoding = "utf-8"  ?> <news> ...
  #1 (permalink)  
Antiguo 21/12/2011, 12:54
 
Fecha de Ingreso: marzo-2007
Mensajes: 782
Antigüedad: 17 años, 1 mes
Puntos: 16
XML parse con PHP simplexml_load_file();

Tengo este codigo, queria saber si es valido o que pasa. Termine con este codigo:

Código PHP:
<?xml version="1.0" encoding="utf-8" ?>
<news>
    
    
    
    <new>
         <title><![CDATA[<a href="/news.php">   First New   </a>]]></title>
        
        <text> If you've got a brain that understands the
complexities of code and an appreciation for
well-designed user experiences, a career in web
technology could be exactly what you're
programmed for. </text>
        <autor>Don't forget me this weekend!</autor>
    </new> 
    
    <new>
         <title><![CDATA[<a href="/news.php">   Second New   </a>]]></title>
        
        <text> In Full Sail University's online Web Design &
Development bachelor's degree program, you'll get
up to speed on industry-standard software and
programming languages, explore</text>
        <autor>Don't forget me this weekend!</autor>
    </new>
    
    <new>
         <title><![CDATA[<a href="/news.php">   Third New   </a>]]></title>
        
        <text> fundamentals of
design and usability, and produce web and mobile
sites from start to finish. You'll launch a digital
portfolio to help engineer your path to a future in the
industry. </text>
        <autor> Don't forget me this weekend!</autor>
    </new>
    
    


    
</news>
Mi php es simple por ahora, es de practica:

Código PHP:
<?php
$xml 
simplexml_load_file('news.xml');

echo 
$xml->new[1]->title;

  
  
?>
Mis mensajes de errores:
Código PHP:
Warningsimplexml_load_file() [function.simplexml-load-file]: news.xml:20parser error xmlParseEntityRefno name in /Applications/XAMPP/xamppfiles/htdocs/news_text.php on line 2

Warning
simplexml_load_file() [function.simplexml-load-file]: <textIn Full Sail Universitys online Web Design in /Applications/XAMPP/xamppfiles/htdocs/news_text.php on line 2

Warning
simplexml_load_file() [function.simplexml-load-file]: ^ in /Applications/XAMPP/xamppfiles/htdocs/news_text.php on line 2 
Ahora cuando solo dejo una noticia <new> </new> y borro las otras 2, si me funciona.

Código PHP:
<?xml version="1.0" encoding="utf-8" ?>
<news>
    
    
    
    <new>
         <title><![CDATA[<a href="www.thechicmagazine.com/news.php">   First New   </a>]]></title>
        
        <text> If you've got a brain that understands the
complexities of code and an appreciation for
well-designed user experiences, a career in web
technology could be exactly what you're
programmed for. </text>
        <autor>Don't forget me this weekend!</autor>
    </new> 
    



    
</news>
  #2 (permalink)  
Antiguo 21/12/2011, 13:01
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: XML parse con PHP simplexml_load_file();

No es válido tu XML sobre todo por las entidades, si te das cuenta en el error te indica que & no se puede interpretar correctamente pues debería ser &amp; ¿notas la diferencia?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 21/12/2011, 13:07
 
Fecha de Ingreso: marzo-2007
Mensajes: 782
Antigüedad: 17 años, 1 mes
Puntos: 16
Respuesta: XML parse con PHP simplexml_load_file();

Gracias, encontre un tutorial de XML y esta obsoleto, otros no explican todo. Necesito algun tutorial para aprender estas cosas con XML y PHP? que use la nueva clase simplexml_load_file() de PHP 5?

Estoy necesitando al menos entender como parsear informacion, como poner links, estilo y entender las reglas de characteres especiales o HTML.

Etiquetas: parse, 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 13:37.