?
Solved

Reading iTunes xml file

Posted on 2006-04-19
13
Medium Priority
?
1,642 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:chris_smith_51
  • 8
  • 5
13 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16485191
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16485218
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
 
LVL 2

Author Comment

by:chris_smith_51
ID: 16485495
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16485614
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
 
LVL 2

Author Comment

by:chris_smith_51
ID: 16486845
<?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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16487020
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
 
LVL 2

Author Comment

by:chris_smith_51
ID: 16487067
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16487070
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16487131
> 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
 
LVL 2

Author Comment

by:chris_smith_51
ID: 16488124
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
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 16488417
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
 
LVL 2

Author Comment

by:chris_smith_51
ID: 16488466
thnkx mate ur a star!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16488680
welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question