Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

XML (WPL) Tool

Name: Anonymous 2006-04-06 20:02

helo world4ch
 
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

Name: Anonymous 2006-04-06 20:23

With Ruby and the REXML library:

require 'rexml/document'
include REXML

file = File.new( 'file.wpl' )
doc = Document.new( file )
doc.elements.each( '//media' ) { |e| puts e.attributes['src'] }
file.close

Name: Anonymous 2006-04-07 4:19

PCRE/<body>.*?<seq>.*?<media src=("[^"]*")/s ?

Name: Anonymous 2006-04-07 7:46

>>2
>>3
thanks, I would prefer a perl solution. if somebody please explain >>3
a bit.

Name: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-04-07 11:51 (sage)

>>9
Sadly, your cheap hack is probably much faster than >>8

Name: Anonymous 2010-09-21 13:17

C# has builtin support for XML.

Name: Anonymous 2010-12-26 15:10

<

Name: Anonymous 2011-02-03 7:02


Don't change these.
Name: Email:
Entire Thread Thread List