SuperCruncher has asked for the wisdom of the Perl Monks concerning the following question:
A few points: directories can contain unlimited directory and file tags. The artist, title etc. tags can exist only inside 'file' tags.<?xml version="1.0" encoding="utf-8"?> <volume device="cdrom" date="2002-02-10" start="d:/" name="Test"> <directory name="Singles"> <file encoding="CBR" stereo="jointstereo" bitrate="192" format="MP +3" name="Metallica - Wherever I May Roam.mp3" size="500000"> <artist>Metallica</artist> <title>Wherever I May Roam</title> <duration>230</duration> <album>Metallica</album> <reldate>1991</reldate> <label>Elektra</label> </file> <file encoding="CBR" stereo="jointstereo" bitrate="192" format="MP +3" name="Linkin Park - In the End.mp3" size="5000000"> <artist>Linkin Park</artist> <title>In The End</title> <duration>250</duration> <album>Hybrid Theory</album> <reldate>1999</reldate> <label>Sony</label> </file> <cover file="front.jpg" format="JPEG" width="100" height="200" side="front"/> <cover file="back.jpg" format="JPEG" width="100" height="200" side="back"/> </directory> <directory name="Cheesy Tunes"> <directory name="Super Cheesy Tunes"> <file encoding="CBR" bitrate="192" name="Village People - YMCA.mp3 +"> </file> </directory> </directory> </volume>
The final application is intended to look something like this screenshot, i.e. a tree with an entry for each volume and each of its subdirectories (recursively). Note in the screenshot that 'Test' and 'Test' are 2 different volumes. When the user clicks on a particular directory, the contents of that directory (whether they are files or more directories) should be displayed in the right-hand pane.
I have implemented this in a rather 'hacked' and far from perfect fashion. In the constructor for my frame, I call a function in package main which sets global variables (using our) in main to store a reference to the tree object and to the current "ID" (the ID is used to denote where an entry into the tree should be inserted), i.e.
I can create the actual tree (with volumes and directories) fine. I used a 'stack' approach, keeping the ID of the next entry to be inserted at the top of the stack, and popping it off whenever an end tag for 'directory' is encountered. (The stack is then cleared before starting another volume.)our (@stack, @directory, %file); our ($treeId, $treeRef, $treeRoot, $lastXMLElement); sub describeTreeObject { ($treeRef, $treeId) = @_; $treeRoot = $treeId; }
The problem is storing data on the files and linking this to what volume they are on, and what the 'properties' of the volume are. The hack I have used is as follows:
Also, if you've read this far, thanks--I know this is a long posting, but I felt it was important to explain the situation as clearly as possible and include all relevant information.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML with wxPerl
by paulbort (Hermit) on Mar 21, 2002 at 21:43 UTC | |
|
Re: XML with wxPerl
by o(o_o)o (Scribe) on Mar 21, 2002 at 20:20 UTC | |
|
Re: XML with wxPerl
by elwarren (Priest) on Mar 21, 2002 at 22:55 UTC |