Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/07/2009, 16:36
Avatar de anf
anf
 
Fecha de Ingreso: junio-2009
Mensajes: 30
Antigüedad: 14 años, 9 meses
Puntos: 4
SimpleXML no lee atributos

Hola amigos, tengo un problema al procesar archivos .xml, tras horas de buscar y buscar y probar y probar muchos códigos (todos los de php.net funcionan con un .xml de ejemplo pero con el mío no) me veo obligado a pediros ayuda por favor.

Tengo un archivo .xml que Flash desde AS 2.0 lo lee perfectamente pero SimpleXML no, os pego los formatos:

mi .xml:

Código:
<?xml version="1.0" encoding="utf-8"?>
<menulist>
	<menuitem img="imagen1.jpg" url="link1.html" id="1" title="Titulo1" text="Descripcion de texto1" />
	<menuitem img="imagen2.jpg" url="link2.html" id="2" title="Titulo2" text="Descripcion de texto2" />
	<menuitem img="imagen3.jpg" url="link3.html" id="3" title="Titulo3" text="Descripcion de texto3" />
</menulist>
Este funciona perfectamente en Flash AS 2.0, pero con SimpleXML no, por los atributos, para que lo lea SimpleXML tengo que tenerlo en este formato:


Código:
<?xml version="1.0" encoding="utf-8"?>
<menulist>
	<menuitem>
		<img>imagen1.jpg</img>
		<url>link1.html</url>
		<id>1</id>
		<title>Titulo1</title>
		<text>Descripcion de texto1</text>
	</menuitem>
	<menuitem>
		<img>imagen2.jpg</img>
		<url>link2.html</url>
		<id>2</id>
		<title>Titulo2</title>
		<text>Descripcion de texto2</text>
	</menuitem>
	<menuitem>
		<img>imagen3.jpg</img>
		<url>link3.html</url>
		<id>3</id>
		<title>Titulo3</title>
		<text>Descripcion de texto3</text>
	</menuitem>
</menulist>
¿alguien sabe que me falta o que estoy pasando por alto? ¿no se puede usar SimpleXML para leer atributos? seguro que es la tontería mas tonta, pego un fragmento de PHP que uso para debug (PHP5):

Código PHP:
/* Formato sin atributos perfecto, dump completo
   pero formato con atributos dump en blanco... */
$xml = new SimpleXMLElement('test.xml'nulltrue);
var_dump($xml); 
dump del que funciona:

Código:
object(SimpleXMLElement)#1 (1) { 
	["menuitem"]=> array(3) { 
		[0]=> object(SimpleXMLElement)#2 (5) { ["img"]=> string(11) "imagen1.jpg" ["url"]=> string(10) "link1.html" ["id"]=> string(1) "1" ["title"]=> string(7) "Titulo1" ["text"]=> string(21) "Descripcion de texto1" } 
		[1]=> object(SimpleXMLElement)#3 (5) { ["img"]=> string(11) "imagen2.jpg" ["url"]=> string(10) "link2.html" ["id"]=> string(1) "2" ["title"]=> string(7) "Titulo2" ["text"]=> string(21) "Descripcion de texto2" } 
		[2]=> object(SimpleXMLElement)#4 (5) { ["img"]=> string(11) "imagen3.jpg" ["url"]=> string(10) "link3.html" ["id"]=> string(1) "3" ["title"]=> string(7) "Titulo3" ["text"]=> string(21) "Descripcion de texto3" } 
	} 
}
Muchas gracias por todo.