I want to create a txt/html file with only the filenames of a wpl-file.
looks like this:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 9.0.0.3344"/>
<title>teh title</title>
</head>
<body>
<seq>
<media src="D:\teh file.mp3" tid="{fjfhdufkbhfudjkjfh}"/>
...
so what I need is a simple xml-tool that allows me to make a query for the "src"
or something that does it automatically
or a hint to let firefox doing it
>>2 >>3
thanks, I would prefer a perl solution. if somebody please explain >>3
a bit.
Name:
Anonymous2006-04-07 9:47
$file = "test.wpl";
open(FH,"<$file") or die "Unable to open file for reading";
while ($i = <FH>) {
next unless $i =~ /media src=([\'\"])([^\'\"]+)\1/;
$filename = $2;
print "$filename\n";
}
close(FH);
# Sample output:
# D:\teh file.mp3
Name:
Anonymous2006-04-07 9:48
Perl-compatible regular expression. You can use that in Perl, PHP, Python, etc. if I haven't failed it. What it does is search <body>,then advance 0 or more characters until the first <seq>, do the sameuntil the first media src=, then capture the quoted text.
Name:
Anonymous2006-04-07 9:59
>>5 probably could use an explaination.
Opens test.wpl.
Read line by line till it encounters a string that matches
media src='randomstuff' or media src="randomstuff".
then prints out randomstuff.
Repeat till end of file.
Name:
Anonymous2006-04-07 10:40
Great !1. While you posted nice solutions I spent some more time to investigeate the masses and masses of information about xml and perl on the internet. Finally I found some nice tutorials and managed to produce a perl script with nearly null knowledge in perl. Now, I share it with you as you did. Thanks again, bye.
#!/usr/bin/perl -w
# use module
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
# read XML file
$data = $xml->XMLin("Favorites -- 4 and 5 star rated.wpl");
# access XML data
foreach my $media (@{$data->{body}->{seq}->{media}}){
print "$media->{src} \n";
}
Name:
Anonymous2006-04-07 11:32 (sage)
>>8
Yea, that's probably a better way of doing it.
My code in >>5 was just a cheap hack.
Name:
Anonymous2006-04-07 11:51 (sage)
>>9
Sadly, your cheap hack is probably much faster than >>8