Pasar consulta SQL a XML predefinido
![Nota Nota](https://perlenespanol.com/foro/styles/prosilver/imageset/icon_post_target.gif)
Buenas, saludos a todos.
Pues básicamente es eso, necesito pasar el resultado de una consulta SQL a un formato XML ya predefinido y escribirlo en un archivo.
La consulta a la base de datos ya la tengo resuelta, pero toda la información que me reporta no sé cómo tratarla y colocarla en el xml con formato ya predefinido.
Intenté utilizar XML::Simple y XML::Schema, pero no lo consigo.
Muchas gracias y saludos a todos...
Resultado de la consulta:
Ejemplo de la lista de reproducción:
Pues básicamente es eso, necesito pasar el resultado de una consulta SQL a un formato XML ya predefinido y escribirlo en un archivo.
La consulta a la base de datos ya la tengo resuelta, pero toda la información que me reporta no sé cómo tratarla y colocarla en el xml con formato ya predefinido.
Intenté utilizar XML::Simple y XML::Schema, pero no lo consigo.
Muchas gracias y saludos a todos...
Using perl Syntax Highlighting
- #!/usr/bin/perl -w
- use strict;
- use DBI;
- my $dsn = 'DBI:ODBC:Driver={SQL Server}';
- my $host = '192.168.1.69,1433';
- my $database = 'Discografia';
- my $user = 'sa';
- my $auth = '';
- #my $fech = strftime;
- # Connectamos via DBD::ODBC by specifying the DSN dynamically.
- my $dbh = DBI->connect("$dsn;Server=$host;Database=$database",
- $user,
- $auth,
- { RaiseError => 1, AutoCommit => 1}
- ) || die "Database connection not made: $DBI::errstr";
- #Preparamos la consulta SQL
- # es una prueba ... my $sql = "SELECT Canal, Config_Canales.Descripcion as Cd from aire,Config_Canales where aire.Canal=Config_Canales.Id and fecha ='2009-01-01' GROUP by Canal, Config_Canales.Descripcion";
- my $sql = "SELECT Canal, Config_Canales.Descripcion AS Cd, Fecha, Categoria, Hora_salida AS Hs, horainicio, Temas.Duracion AS Td, interprete, Temas.Titulo, codigo_cd AS Ccd FROM aire,Config_Canales,Temas where aire.Canal=Config_Canales.Id and aire.Codigo_cd=Temas.idDiscoCorte and fecha ='2009-01-01' order by Canal, Cd, horainicio ASC";
- my $sth = $dbh->prepare( $sql );
- #Execute the statement
- $sth->execute();
- # es una prueba ... my( $Canal, $Cd );
- my( $Canal, $Cd, $Fecha, $Categoria, $Hs, $horainicio, $Td, $interprete, $titulo, $Ccd );
- # Bind the results to the local variables
- #es una prueba . . .$sth->bind_columns( undef, \$Canal, \$Cd );
- $sth->bind_columns( undef, \$Canal, \$Cd, \$Fecha, \$Categoria, \$Hs, \$horainicio, \$Td, \$interprete, \$titulo, \$Ccd );
- #Retrieve values from the result set
- while( $sth->fetch() ) {
- print "$Canal, $Cd, $Fecha, $Categoria, $Hs, $horainicio, $Td, $interprete, $titulo, $Ccd\n";
- };
- $sth->finish();
- $dbh->disconnect();
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
Resultado de la consulta:
Using text Syntax Highlighting
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:29:30.000, 1899-12-30 05:26:51.000, 239, MAXWELL, THE URBAN THEME, 01432801
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:34:24.000, 1899-12-30 05:29:30.000, 448, LOUNGE CAFE, FORMENTERA AMBIANCE, 01526001
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:40:15.000, 1899-12-30 05:34:18.000, 551, GOLOKA, GIVE ME LOVING, 01541507
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:44:55.000, 1899-12-30 05:40:09.000, 445, JONATHAN BADICHI, BLACK MUSIC, 01289910
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:48:55.000, 1899-12-30 05:44:54.000, 357, BLANK & JONES, MIND OF THE WONDERFUL, 01469203
- 23, 023 - (RMS) MEDITERRANEO 2009-01-01 00:00:00.000, 5201, 1899-12-30 05:51:28.000, 1899-12-30 05:48:51.000, 237, DUSTY SPRINGFIELD, SPOOKY, 00970006
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
Ejemplo de la lista de reproducción:
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <PLAYLISTS>
- <PLAYLIST canal="1" nombrecanal=" 301 (SAT) SOLO MUSICA" web="0">
- <CANCION fecha="04/09/2012 00:00:00" duracion="230" categ="0" interprete="PEDRO JAVIER GONZALEZ" titulo="MASSACHUSSETS">/home/musicam/ogg/01136508.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:02:30" duracion="621" categ="0" interprete="KENNY G" titulo="PERUVIAN NIGHTS">/home/musicam/ogg/01535306.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:08:46" duracion="35" categ="0" interprete="FRANCIS WHITE" titulo="THE BREEZE AND I">/home/musicam/ogg/02001311.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:11:51" duracion="347" categ="0" interprete="101 STRINGS" titulo="ORQUIDEAS A LA LUZ DE LA LUNA">/home/musicam/ogg/02002603.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:15:38" duracion="129" categ="0" interprete="ENNIO MORRICONE" titulo="BROTHERS">/home/musicam/ogg/00712805.ogg</CANCION>
- </PLAYLIST>
- <PLAYLIST canal="2" nombrecanal=" 302 (SAT) SELECCIONES MUSICALES" web="0">
- <CANCION fecha="04/09/2012 00:00:00" duracion="324" categ="0" interprete="SERGIO RIVERO" titulo="LA LLAVE DE TU CORAZON">/home/musicam/ogg/01320604.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:03:24" duracion="316" categ="0" interprete="BOB SINCLAR/STEVE EDWARDS" titulo="WORLD, HOLD ON">/home/musicam/ogg/01366701.ogg</CANCION>
- <CANCION fecha="04/09/2012 00:06:40" duracion="349" categ="0" interprete="BEN S BROTHER" titulo="LET ME OUT">/home/musicam/ogg/01502101.ogg</CANCION>
- </PLAYLIST>
- </PLAYLISTS>
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4