Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: Crack_X en 5 Junio 2007, 23:15 pm



Título: XML, RSS
Publicado por: Crack_X en 5 Junio 2007, 23:15 pm
Hay alguna clase para parsear xml y un pequeno ejemplo? estuve buscando y encontre una en php.net pero no estoy seguro si viene incluido en todos los php o hay que instalarlo adicionalmente.

Saludos,
Crack_X


Título: Re: XML, RSS
Publicado por: alone-in-the-chat en 5 Junio 2007, 23:59 pm



http://foro.elhacker.net/index.php/topic,155881.0.html
 (http://foro.elhacker.net/index.php/topic,155881.0.html)

Si me acordaba haber puesto una
n_n

Saludos.


Título: Re: XML, RSS
Publicado por: Crack_X en 9 Junio 2007, 06:44 am
Volviendo con el tema... estoy intentando esto:

Código:
	<?php	

$xml = file_get_contents('feed.xml');


// Callback functions from reader
// ==============================

$flag = array();
$g = "";
function elementStart($parser, $tag, $attributes) {

echo "STARTED tag " . $tag . "<br/>";
$flag[$tag] = "";
$g = $tag;
}

function elementEnd($parser, $tag) {

echo "Ended tag " . $tag . "<br/>";


}

function cdata($parser, $data) {

echo "Data " . $data . "<br/>";
$flag[$g] = $data;
}

$parser = xml_parser_create();

// Setup end/start handlers
xml_set_element_handler($parser,"elementStart","elementEnd");

// Ok we need to handle character data
xml_set_character_data_handler($parser,"cdata");
xml_parse($parser, $xml);
xml_parser_free($parser);

echo $flag["TITLE"] . "TEST";
?>

Pero no sale nada en $flag["TITLE"] y si existe un tag llamado title. Alguna sugerencia de como hacerlo?


Título: Re: XML, RSS
Publicado por: sirdarckcat en 9 Junio 2007, 08:58 am
usa preg_match xD
hice un parser sencillo para el bot de me****, y si quieres las expresiones regulares, en warzone, ve el codigo de reporter.js

sin embargo, si quieres usar las funciones nativas de php, son estas.. www.php.net/xml
es necesario que pongas aqui que feed.xml estas usando :P

Saludos!!


Título: Re: XML, RSS
Publicado por: Crack_X en 9 Junio 2007, 21:03 pm
Estoy usando un feed de wordpress, rss2.0.  Y creo que estoy usando las funciones nativas o me equivoco?  :P Me he dado cuenta que con Ajax es completamente mas facil de hacer pero quiero terminar lo que empese :P


Título: Re: XML, RSS
Publicado por: deya en 11 Junio 2007, 18:18 pm
Existen 3 API's para el manejo de PHP y XML:

1) API DOM

2) API SAX

3) API Simple XML

Si quieres aprender a utilizarlas, te recomiendo veas o descargues los VT's 40, 41 y 42 del curso de Php y MySQL en http://www.illasaron.com/html (http://www.illasaron.com/html)

Salu2  ;)