Foros del Web » Programando para Internet » PHP »

leer xml

Estas en el tema de leer xml en el foro de PHP en Foros del Web. buenas: tengo que leer de una direccion como esta: matchesArchive.asp?outputType=XML&actionType=view una estructura xml, en la ayuda de la pagina que tengo que obtener los datos ...
  #1 (permalink)  
Antiguo 22/06/2007, 20:29
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
leer xml

buenas:
tengo que leer de una direccion como esta:
matchesArchive.asp?outputType=XML&actionType=view
una estructura xml, en la ayuda de la pagina que tengo que obtener los datos me dice esto:


Syntax

matchesArchive.asp?
outputType = {HTML | XML}
actionType = {view | viewCup}
[teamID = integer]
[FirstMatchDate = Date]
[LastMatchDate = Date]
[Season = integer]



Indata parameters

outputType
Indicates whether the output to the client should be an HTML document or an XML file. Only the XML document may be used for CHPP use.

actionType
Indicates what type of action the page should perform.

Value Default Description
view Default View the match list of the team.
viewCup View the match list, cup matches, in a specific season for the team.


teamID
What team to show the matches for.

FirstMatchDate
First date to show matches in archive from. Default is three months ago.

LastMatchDate
Last date to show matches in archive to. Default is last midnigt. If more than 50 matches have occured since FirstMatchDate, only the 50 first will be returned.

Season
Which season to show cup matches for.


Outdata parameters

The XML output can contain the following tags/containers:

HattrickData
Generic tag wrapped around all XML data from Hattrick.

FileName (Within HattrickData)
The name of the file that your request was sent to.

UserID (Within HattrickData)
The logged on User's UserID (not to be confused with TeamID). If not logged on, it defaults to 0.

Version (Within HattrickData)
The current version number of the XML output.

FetchedDate (Within HattrickData)
Date and time when the XML file was fetched. Format is YYYY-MM-DD HH:MM:SS, unless HH:MM:SS is 00:00:00 - then the format is YYYY-MM-DD

ActionType (Within HattrickData)
The initial actionType that was submitted for the page.

Team (Within HattrickData)
The team that the list applies to.

TeamID (Within Team)
The team's TeamID.

TeamName (Within Team)
The full name of the team.

FirstMatchDate (Within Team)
First date to show matches in archive from.

LastMatchDate (Within Team)
Last date to show matches in archive to.

MatchList (Within Team)
Container for the matches. An Attribute called Count specifies how many matches it contains. If more than 50 matches have occured between FirstMatchDate and LastMatchDate, only the 50 first will be returned.

Match (Within MatchList)
A match. An attribute called Index signifies the number of the match in the list (not to be confused with MatchID which is globally unique).

MatchID (Within Match)
The globally unique identifier of the match.

HomeTeam (Within Match)
The Home (formal, not taking arena location into account) team of the match.

HomeTeamID (Within HomeTeam)
The teamID of the Home team in the match.

HomeTeamName (Within HomeTeam)
The team name of the Home team in the match.

AwayTeam (Within Match)
The away (formal, not taking arena location into account) team of the match.

AwayTeamID (Within AwayTeam)
The teamID of the away team in the match.

AwayTeamName (Within AwayTeam)
The team name of the away team in the match.

MatchDate (Within Match)
The start date (kick-off) of the match.

MatchType (Within Match)
Integer defining the type of match:


HomeGoals (Within Match)
The number of goals for the home team. If the match is still upcoming or ongoing, this tag is not sent.

AwayGoals (Within Match)
The number of goals for the away team. If the match is still upcoming or ongoing, this tag is not sent

Examples

Requests may be posted as either GET or POST.

Get the data for a specified team
matchesArchive.asp?outputType=XML&actionType=view& teamID=373 Try

Get the data for your own team
matchesArchive.asp?outputType=XML&actionType=view Try

Get the data for your own team for february 2004
matchesArchive.asp?outputType=XML&FirstMatchDate=2 004-02-01&LastMatchDate=2004-03-01 Try


Como puedo manejar todo esa informacion en php?
Espero que se entienda lo que quiero hacer y que me puedan dar una mano.
Desde ya muchas gracias
  #2 (permalink)  
Antiguo 23/06/2007, 10:17
 
Fecha de Ingreso: junio-2005
Mensajes: 981
Antigüedad: 18 años, 10 meses
Puntos: 2
Re: leer xml

No entiendo que es lo que quieres con todos eso que has puesto. Sobre manejar XML's creo que es bastante simple, buscas en Google y encontraras mucha info. En modo reducido, se puede manejar de dos maneras... DOM, todo el XML se convierte en un objeto y trabajas con el objeto, la ventaja es que es mucho más fácil agregar y sacar cosas y la desventaja es que consume mucho recursos... y SAX, va abriendo y cerrando tag del XML y vas leyendo al vuelvo la ventaja es que consume poca recursos y la desventaja es que es difícil de entender al principio. Dependiendo del tamaño yo te recomendaría DOM.

Espero te sirva de algo.

Saludos.
  #3 (permalink)  
Antiguo 23/06/2007, 10:17
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Re: leer xml

Buenas jatriquero

Te recomiendo una "vichada" a las funciones DOM de PHP:

http://php.net/dom si estás usando PHP5
http://www.php.net/manual/es/ref.domxml.php para PHP4, en este caso necesitás tener una instalación correcta de libxml (a veces está pero no funciona ... )

Con eso podés ir obteniendo los datos tal cual como lo hacés con Javascript (getElementsByTagName, getElementById). También deberías guardar una copia del XML recibido para tener un ejemplo claro siempre a mano.

Yo en su momento me metí con eso también, aunque no llegué muy lejos porque no tenía el tiempo necesario para el proyecto.


Saludos.
  #4 (permalink)  
Antiguo 23/06/2007, 10:36
 
Fecha de Ingreso: junio-2007
Ubicación: Mérida, Yucatán, México
Mensajes: 94
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: leer xml

Según entendí, la página matches... te devuelve todo ese rollo, tal vez por que te hace falta que le pases más parametros como el teamID... me imagino que una vez con eso, te podrá devolver un archivo XML, y podrás trabajar con los datos,... Como dicen los demás puedes buscar un buen tutorial XML como puede ser:

www . phpbsd . net /2007/02/09/leyendo-xml-desde-php-con-simplexml/

Nota:Los separé con un espacio por que no me deja aún poner enlaces...

Espero te sirva
  #5 (permalink)  
Antiguo 23/06/2007, 12:50
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Re: leer xml

a ver si me explico mejor, lo que quiero hacer es una aplicacion para hattrick.org en php, el juego se maneja con xml, pero no existe un arhivo.xml sino que se genera a partir de una direccion web.
Lo que no entiendo despues de leer la info sobre simplexml es como leo el xml desde la direccion web para que me devuelva toda esa chorrera de datos.
Se entiende ahora. Me fijo en los url que me pasaron para ver si encuetro algo que me sirva.

salu2
  #6 (permalink)  
Antiguo 23/06/2007, 13:34
 
Fecha de Ingreso: junio-2005
Mensajes: 981
Antigüedad: 18 años, 10 meses
Puntos: 2
Re: leer xml

Cita:
Iniciado por destor77 Ver Mensaje
a ver si me explico mejor, lo que quiero hacer es una aplicacion para hattrick.org en php, el juego se maneja con xml, pero no existe un arhivo.xml sino que se genera a partir de una direccion web.
Lo que no entiendo despues de leer la info sobre simplexml es como leo el xml desde la direccion web para que me devuelva toda esa chorrera de datos.
Se entiende ahora. Me fijo en los url que me pasaron para ver si encuetro algo que me sirva.

salu2
Si es una dirección web lo abres con fopen() y una vez que tienes todo el contenido lo manipulas como quieras.

Saludos.
  #7 (permalink)  
Antiguo 23/06/2007, 17:08
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Re: leer xml

Cita:
Yo en su momento me metí con eso también, aunque no llegué muy lejos porque no tenía el tiempo necesario para el proyecto.
Y pudiste hacer algo? como para continuarlo?
  #8 (permalink)  
Antiguo 23/06/2007, 17:17
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Re: leer xml

Cita:
Iniciado por DarioDario
Si es una dirección web lo abres con fopen() y una vez que tienes todo el contenido lo manipulas como quieras
Saludos.
Intente de esta forma:
Código PHP:
$file fopen('http://www89.hattrick.org/Common/matchesArchive.asp?outputType=XML&actionType=view&teamID=373','r');
$xml simplexml_load_string($file);
var_dump($xml); 
Y me tira este error:
Warning: simplexml_load_string() expects parameter 1 to be string, resource given in D:\xampp\htdocs\chpp\team.php on line 131
NULL

porque es? que parametro espera?
  #9 (permalink)  
Antiguo 23/06/2007, 18:45
 
Fecha de Ingreso: junio-2005
Mensajes: 981
Antigüedad: 18 años, 10 meses
Puntos: 2
Re: leer xml

Cita:
Iniciado por destor77 Ver Mensaje
Y me tira este error:
Warning: simplexml_load_string() expects parameter 1 to be string, resource given in D:\xampp\htdocs\chpp\team.php on line 131
NULL

porque es? que parametro espera?
Esta bien ese error. La función espera un String como parámetro y vos le estas pasando el recurso al archivo abierto.

Lee:
http://www.php.net/manual/es/function.fopen.php
http://www.php.net/manual/es/function.fgets.php
http://www.php.net/manual/es/function.fgetc.php
http://www.php.net/manual/es/function.fread.php

Con lo anterior deberías ser capaz de trabajar con archivos. Solo a modo de agregar algo, también tienes la función file(), poco te ayudara en este problema particular, pero es bueno saber que existe.

Saludos.
  #10 (permalink)  
Antiguo 23/06/2007, 18:47
 
Fecha de Ingreso: junio-2005
Mensajes: 981
Antigüedad: 18 años, 10 meses
Puntos: 2
Re: leer xml

Ufff... como se me pudo haber pasado?, en esta situación la función file_get_contents() te vendría barbaro.

Saludos.
  #11 (permalink)  
Antiguo 24/06/2007, 13:07
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Re: leer xml

Cita:
Iniciado por destor77 Ver Mensaje
Y pudiste hacer algo? como para continuarlo?
No, nada que valga la pena.

Tal y como te lo dijeron, lo ideal es usar file_get_contents(), ya que con una sola función obtenés en una cadena el contenido del archivo.

No olvides que tenés que mandar en el User-Agent el nombre de tu programa, quizás más adelante tengas que usar

http://www.php.net/manual/es/functio...ext-create.php

Y aunque no tenga que ver con el problema puntual, acordate que lo primero que tenés que pedir a www.hattrick.org es el listado de servidores para saber a cuál conectarte.
Te recomiendo ver el foro de CHPP en HT, hay un listado de preguntas frecuentes que te explican muchos detalles.


Saludos.
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 19:48.