Foros del Web » Programando para Internet » PHP »

obtener datos de un xml con php

Estas en el tema de obtener datos de un xml con php en el foro de PHP en Foros del Web. tengo un xml parecido al siguiente @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código XML: Ver original <?xml version = '1.0' encoding = 'UTF-8' ?>     <feed >   ...
  #1 (permalink)  
Antiguo 14/02/2011, 15:50
Avatar de juanito1712  
Fecha de Ingreso: mayo-2010
Ubicación: Valencia
Mensajes: 1.124
Antigüedad: 13 años, 11 meses
Puntos: 66
obtener datos de un xml con php

tengo un xml parecido al siguiente
Código XML:
Ver original
  1. <?xml version='1.0' encoding='UTF-8'?>
  2.     <feed>
  3.         <entry>
  4.             <id></id>
  5.            
  6.             <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
  7.             <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='People' label='Gente y blogs'/>
  8.             <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='buenafuente'/>
  9.             <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='la sexta'/>
  10.             <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='andreu buenafuente'/>
  11.             <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='gala goya'/>
  12.            
  13.             <media:group>
  14.                 <media:category label='Gente y blogs' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>People</media:category><media:content url='http://www.youtube.com/v/cEyFx_rVChk?f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='133' yt:format='5'/>
  15.                 <media:content url='rtsp://v5.cache5.c.youtube.com/CiILENy73wIaGQkZCtX6x4VMcBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='133' yt:format='1'/>
  16.                 <media:content url='rtsp://v4.cache2.c.youtube.com/CiILENy73wIaGQkZCtX6x4VMcBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='133' yt:format='6'/>
  17.                 <media:description type='plain'></media:description>
  18.                 <media:keywords>buenafuente, la sexta, andreu buenafuente, gala goya</media:keywords>
  19.                 <media:player url='http://www.youtube.com/watch?v=cEyFx_rVChk&amp;feature=youtube_gdata_player'/>
  20.                 <media:thumbnail url='http://i.ytimg.com/vi/cEyFx_rVChk/0.jpg' height='240' width='320' time='00:01:06.500'/>
  21.                 <media:thumbnail url='http://i.ytimg.com/vi/cEyFx_rVChk/1.jpg' height='90' width='120' time='00:00:33.250'/>
  22.                 <media:thumbnail url='http://i.ytimg.com/vi/cEyFx_rVChk/2.jpg' height='90' width='120' time='00:01:06.500'/>
  23.                 <media:thumbnail url='http://i.ytimg.com/vi/cEyFx_rVChk/3.jpg' height='90' width='120' time='00:01:39.750'/>
  24.                 <media:title type='plain'>Buenafuente encargado de presentar los Goya</media:title>
  25.                 <yt:duration seconds='133'/>
  26.             </media:group>
  27.         </entry>
  28.     </feed>

soy capaz de acceder a varias etiquetas pero me resulta imposible obtener los de los campos que tienen : o los campos que no tienen contenido en su interior sino como una propiedad de la etiqueta

alguien sabe como se hace eso?

yo tengo esto
Código PHP:
Ver original
  1. $xml = simplexml_load_file($yt_urltot);
  2. //$xml = str_replace("media:","mediax",$xml);
  3. foreach ($xml->entry as $message){
  4. print("<div style='border:solid 1px #000000'>");
  5. print("<p style='color:red;'>".$message->title.'</p>');
  6. print("<p style='color:red;'>".$message->content.'</p>');
  7. print("<p style='color:red;'>".$message->author->name.'</p>');
  8. print("</div>");
  9. }

He tratado de hacer el reemplazo que se ve comentado pero no va tampoco
  #2 (permalink)  
Antiguo 14/02/2011, 15:53
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: obtener datos de un xml con php

podrías usar var_dump() para analizar la estructura antes de recorrerla...

además te sugiero leer las normas del foro, ya que no esta permitido duplicar temas:
http://www.forosdelweb.com/f18/api-y...on-xml-885935/
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.

Etiquetas: 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 04:44.