Reading iTunes xml file

Rite - never even touched xml bfore so please help me! I wanted my friends iTunes music library so that i could pick ones out for my own ipod. He exported his library and emailed it to me as an xml file - iTunes won't have it any other way unfortunately. I thought that by importing this into my library i would be able to see all the songs, but not have them on my ipod. This isnt the case though, as i just get all his playlists with only some songs listed (the ones already on my computer). I can open the xml file in my broswer and view everything but it is just meaningless to me. I need it in readable form as there are over 2000 songs listed here. The general code per song looks something like this:

- <dict>
  <key>Track ID</key>
  <integer>36</integer>
  <key>Name</key>
  <string>Crazy In Love</string>
  <key>Artist</key>
  <string>Beyoncé</string>
  <key>Album</key>
  <string>Dangerously In Love</string>
  <key>Genre</key>
  <string>R&B/Soul</string>
  <key>Kind</key>
  <string>AAC audio file</string>
  <key>Size</key>
  <integer>4268823</integer>
  <key>Total Time</key>
  <integer>235890</integer>
  <key>Disc Number</key>
  <integer>1</integer>
  <key>Disc Count</key>
  <integer>1</integer>
  <key>Track Number</key>
  <integer>1</integer>
  <key>Track Count</key>
  <integer>17</integer>
  <key>Year</key>
  <integer>2003</integer>
  <key>Date Modified</key>
  <date>2005-08-21T23:46:19Z</date>
  <key>Date Added</key>
  <date>2005-10-17T19:53:16Z</date>
  <key>Bit Rate</key>
  <integer>128</integer>
  <key>Sample Rate</key>
  <integer>44100</integer>
  <key>Play Count</key>
  <integer>80</integer>
  <key>Play Date</key>
  <integer>-1071557161</integer>
  <key>Play Date UTC</key>
  <date>2006-02-21T22:42:15Z</date>
  <key>Normalization</key>
  <integer>3551</integer>
  <key>Artwork Count</key>
  <integer>1</integer>
  <key>Season</key>
  <integer>0</integer>
  <key>Persistent ID</key>
  <string>SOME ID NUMBER</string>
  <key>Disabled</key>
  <true />
  <key>Track Type</key>
  <string>File</string>
  <key>Location</key>
  <string>LOCATION PATH</string>
  <key>File Folder Count</key>
  <integer>4</integer>
  <key>Library Folder Count</key>
  <integer>1</integer>
  </dict>
  <key>37</key>
- <dict>

Now is there any way to convert this into a table (preferably html) or get iTunes to print off each song in a nice way, or just do ANYTHING to make it so that i can read each file easily?!?

Thanks,
Chris
LVL 2
chris_smith_51Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Hi chris_smith_51,

this XSLT will transform the above XML into a reasonable html table

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <html>
            <body>
                <table border="1">
                    <xsl:apply-templates select="//*[local-name() = 'dict']"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="//*[local-name() = 'dict']">
        <tr>
            <td><xsl:value-of select="key[text() = 'Track ID']/following-sibling::*[1]"/></td>
            <td><xsl:value-of select="key[text() = 'Name']/following-sibling::*[1]"/></td>
            <td><xsl:value-of select="key[text() = 'Artist']/following-sibling::*[1]"/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>


Cheers!
0
Geert BormansInformation ArchitectCommented:
chris_smith_51,

maybe the best thing you can do is this
save the above XSLT as a file: table.xsl
put the xslt in the same directory as your xml file
edit the xml and put this line as a second line in your xml file

<?xml-stylesheet type="text/xsl" href="table.xsl"?>

with second line I ean, it should come immedeatly after the line saying something like this

<?xml version....

if your XML lacks that line, put the <?xml-stylesheet... as the first line

should give you your table

cheers

Geert
0
chris_smith_51Author Commented:
Hi Geert,

I have done what you suggested and now i get this error:


The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Access is denied. Error processing resource 'file:///C:/Documents and Settings/christopher.smith/Desktop/table.xsl'.

 

Any ideas?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Geert BormansInformation ArchitectCommented:
well, there are possibilities
- something is holding a lock on the file
- the file is not at that location
- the file has a different name

can you post the 5 first lines of your XML file?

cheers
0
chris_smith_51Author Commented:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="table.xsl"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
      <key>Major Version</key><integer>1</integer>
      <key>Minor Version</key><integer>1</integer>
      <key>Application Version</key><string>6.0.1</string>
0
Geert BormansInformation ArchitectCommented:
There is no need for validating the DTD
so you can better remove it (I checked, there is nothing in there that would be use by the browser)

so change the heading part to

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="table.xsl"?>
<plist version="1.0">
<dict>

which browser are you using?

cheers

Geert
0
chris_smith_51Author Commented:
still doesnt work :( Im using IE - latest version. I have previously dealt with ASP and PHP which must be run through a web server - is this the same with XML?
0
Geert BormansInformation ArchitectCommented:
works like acharm for me in Internet Explorer and FireFox.
I constructed the XML from what you posted
and had to change some things (the usual copy issues from this forum's pages)
- the dashes before the collapsable elements require removal
- & needs to be &amp;, é is in the wrong encoding...
but I assume that you don't have those issues if you copied the right XML

cheers

what platform are you on?
do you have msxml4 installed? you can download that from the microsoft website, not a bad idea
0
Geert BormansInformation ArchitectCommented:
> run through a web server - is this the same with XML?
no, not at all, it should be fine statically
it could be a security issue if you are on windows XP

anyway
there are other and maybe better options

- download and install msxml4 from the microsoft website
- download and install msxsl from the microsoft website
- set a path to where the msxsl.exe is
- transform your XML using the XSLT I gave, something like
   F:\path\msxsl table.xml table.xsl -o table.html

the html file will be in table.html then
(you might have to change the filename and path)

cheers

Geert
0
chris_smith_51Author Commented:
all works! notepad seemed to add loads of characters into it for some reason and when opened in frontpage and resaved everything appears very nicely and the code is much cleaner too. thanks very much! one more thing though - iTunes has given each track an ID number and the table lists the songs in ascending ID order. can i change this to either ascending track or artist order?

cheers
0
Geert BormansInformation ArchitectCommented:
yep,

I slightly changed the stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="order">Name</xsl:param>
    <xsl:template match="/">
        <html>
            <body>
                <table border="1">
                    <xsl:apply-templates select="//*[local-name() = 'dict']">
                        <xsl:sort select="key[text() = $order]/following-sibling::*[1]"/>
                    </xsl:apply-templates>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="//*[local-name() = 'dict']">
        <tr>
            <td><xsl:value-of select="key[text() = 'Track ID']/following-sibling::*[1]"/></td>
            <td><xsl:value-of select="key[text() = 'Name']/following-sibling::*[1]"/></td>
            <td><xsl:value-of select="key[text() = 'Artist']/following-sibling::*[1]"/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

it now orders by 'Name'
If you want Artist, you need to replace this line
<xsl:param name="order">Name</xsl:param>
with this line
<xsl:param name="order">Artist</xsl:param>
(note: case sensitive)

even better, if you use the msxsl option, you can pass a parameter
and choose your ordering at will
F:\path\msxsl table.xml table.xsl -o table.html order='Name'
or
F:\path\msxsl table.xml table.xsl -o table.html order='Artist'

cheers


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chris_smith_51Author Commented:
thnkx mate ur a star!
0
Geert BormansInformation ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.