"Johnny Yu" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> hello.
>
> i am new with perl and working on a program to sort and manage my dvds
> instead of using windows program. i export the windows data using built
in
> function to make it xml, how can i read this with perl so i can put in
> mysql? i try xml::simple but it doesn't work. can someone show me
example
> program? i know how to do the mysql part.
>
> this is what xml output looks like:
>
<snip />
Heres your program. You need to install and STUDY THE DOCS for XML::XPath
and DBI:
use warnings;
use strict;
use XML::XPath;
# use DBI;
my $xp = XML::XPath->new( xml => join( '', <DATA> ) );
#my $dbh = DBI->connect( ... );
#my $sql = 'INSERT INTO dvds (?, ?, ?, ?)';
#my $sth = $dbh->prepare( $sql );
my $entries = $xp->find('DVDListXML/playlist/entry');
foreach my $node ( $entries->get_nodelist ) {
my $Infostring = $xp->findvalue('./@Infostring', $node);
my $Name = $xp->findvalue('Name', $node);
my $Genre = $xp->findvalue('Genre', $node);
my $Runtime = $xp->findvalue('Runtime', $node);
# $sth->execute( $Infostring, $Name, $Genre, $Runtime );
print( 'Name: ', $Name, "\n" );
print( "\t", 'Info: ', 'http://...', "\n" ); # $Infostring
print( "\t", 'Genre: ', $Genre, "\n" );
print( "\t", 'Runtime: ', $Runtime, "\n" );
}
__DATA__
<?xml version="1.0" encoding='UTF-8' standalone="yes"?>
<DVDListXML>
<playlist num_entries="3" label="DVDs">
<entry
Infostring="http://a9.com/Star%20Wars:%20Episode%20IV%20-%20A%20New%20Hope?i
mdbid=tt0076759">
<Name>Star Wars: Episode IV - A New Hope</Name>
<Genre>Science Fiction</Genre>
<Runtime>121</Runtime>
</entry>
<entry
Infostring="http://a9.com/Star%20Wars:%20Episode%20V%20-%20The%20Empire%20St
rikes%20Back%20(1980)?imdbid=tt0080684">
<Name>Star Wars: Episode V - The Empire Strikes Back</Name>
<Genre>Science Fiction</Genre>
<Runtime>128</Runtime>
</entry>
<entry
Infostring="http://a9.com/Star%20Wars:%20Episode%20VI%20-%20Return%20of%20th
e%20Jedi?imdbid=tt0086190">
<Name>Star Wars: Episode VI - Return of the Jedi</Name>
<Genre>Science Fiction</Genre>
<Runtime>134</Runtime>
</entry>
</playlist>
</DVDListXML>
Heres the output:
C:\waveright\home\trwww\misc>perl movies.pl
Name: Star Wars: Episode IV - A New Hope
Info: http://...
Genre: Science Fiction
Runtime: 121
Name: Star Wars: Episode V - The Empire Strikes Back
Info: http://...
Genre: Science Fiction
Runtime: 128
Name: Star Wars: Episode VI - Return of the Jedi
Info: http://...
Genre: Science Fiction
Runtime: 134
Have fun,
Todd W.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>