XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2003, 09:49 AM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
Transforming Key/Value pairs with XSL (i.e iTunes xml file)

I'm trying to figure out the best way to transform an XML file that has the structure of Key value pairs. In particular, any programs on MAC OSX that support xml export. For those of you not familar, something like my iTunes library would look like this:
PHP Code:
<dict>
   <
key>0</key>
   <
dict>
      <
key>Track ID</key><integer>33</integer>
            <
key>Name</key><string>Turnover</string>
            <
key>Artist</key><string>Fugazi</string>
            <
key>Album</key><string>Repeater 3 Songs</string>
            <
key>Genre</key><string>Alternative Punk</string>
            <
key>Kind</key><string>MPEG audio file</string>
            <
key>Size</key><integer>5123239</integer>
            <
key>Total Time</key><integer>256052</integer>
            <
key>Disc Number</key><integer>1</integer>
            <
key>Track Number</key><integer>1</integer>
            <
key>Track Count</key><integer>14</integer>
            <
key>Year</key><integer>1990</integer>
            <
key>Date Modified</key><date>2003-02-06T05:01:28Z</date>
            <
key>Date Added</key><date>2003-02-06T04:59:47Z</date>
            <
key>Bit Rate</key><integer>160</integer>
            <
key>Sample Rate</key><integer>44100</integer>
            <
key>Play Count</key><integer>4</integer>
            <
key>Play Date</key><integer>-1153856238</integer>
            <
key>Play Date UTC</key><date>2003-07-15T14:50:58Z</date>
            <
key>Normalization</key><integer>2379</integer>
            <
key>File Type</key><integer>1297106739</integer>
            <
key>File Creator</key><integer>1752133483</integer>
            <
key>Location</key><string>./Fugazi/Repeater%20+%203%20Songs/1-01%20Turnover.mp3</string>
            <
key>File Folder Count</key><integer>4</integer>
<
key>Library Folder Count</key><integer>1</integer>

   </
dict>
</
dict


Now rather than the XML file being structured like I would think, (i.e)
PHP Code:
<library>
  <
artist>
    <
name>Fugazi</name>
    <
albums>
       <
album>
         <
AlbumName>Repeater</AlbumName>
         <!-- 
etc... --> 
    </
albums>
  </
artist>
</
library


How can effectively display the information the way that it is using XSL? Is it possible to use XSL to display the key/value pairs? Should I write a better XML export for each application that structures the data more representative of how it should be? A side question to this, is why is the data represented like this in Apple's export? Is it really a better way to store the data? Or is it just that they are lazy and didn't want to customize the XML export to each application? Rather than just have an export that turns the datafile of an application into an XML file so you can do more with it? Anyway, thanks for your time and any help would be greatly appreciated.

Reply With Quote
  #2  
Old September 11th, 2003, 12:26 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Yes, it's a cop out. Not only that, but it's really sucky xml. Here's an xsl file will turn it into non-sucky (but still copped-out) xml.
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/dict/dict/key">
	<element key="{.}">
		<xsl:value-of select="following-sibling::node()" />
	</element>
	
</xsl:template>

<xsl:template match="text()">
	<!-- skip all text -->
</xsl:template>

</xsl:stylesheet>

The problem with turning it directly into a format similar to what you described is that some of the element keys contain spaces, so they can't be element names. You should be able to either 1) perform a second transform that structures the data properly or 2) use the same technique with some logic thrown in that generates appropriate element names.

Apple really should provide better export capability. The format they have now is rather difficult to work with. There's no apparent relationship between keys and values, since XML (generally) only understands heirarchies.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Transforming Key/Value pairs with XSL (i.e iTunes xml file)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway