views:

33

answers:

1

So, basically I want to make objects "Songs" from iTunes Library.xml The problem is that XML-file looks more like .plist Here is an example:

<key>56</key>
    <dict>
        <key>Track ID</key><integer>56</integer>
        <key>Name</key><string>apple-ipad-video</string>
        <key>Kind</key><string>QuickTime Movie</string>
        <key>Size</key><integer>99552974</integer>
        <key>Total Time</key><integer>440607</integer>
        <key>Date Modified</key><date>2010-05-13T19:55:21Z</date>
        <key>Date Added</key><date>2010-07-22T05:40:11Z</date>
        <key>Bit Rate</key><integer>123</integer>
        <key>Artwork Count</key><integer>1</integer>
        <key>Persistent ID</key><string>EEC08DC8DE950DF9</string>
        <key>Track Type</key><string>File</string>
        <key>Has Video</key><true/>
        <key>HD</key><false/>
        <key>Video Width</key><integer>848</integer>
        <key>Video Height</key><integer>480</integer>
        <key>Movie</key><true/>
        <key>Location</key><string>file://localhost/Users/User/Music/iTunes1/iTunes%20Media/Movies/apple-ipad-video-geo-alt1-ru-20100406_848x480/apple-ipad-video-geo-alt1-ru-20100406_848x480.mov</string>
        <key>File Folder Count</key><integer>4</integer>
        <key>Library Folder Count</key><integer>1</integer>
    </dict>
    <key>58</key>

How can I parse it when all the elements are same? I need object in output that looks something like this:

@interface Song : NSObject {
    NSInteger *trackID;
    NSString *name;
    NSString *kind;
    NSInteger *size;
    ...
}

Anybody got ideas? Thanks in advance.

+1  A: 

Read it as a plist and then extract the data you need from it.

Song *mySong = [[Song alloc]init];
NSString *filename = @"/path/to/the/file.xml";
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:filename];

NSLog(@"Read in plist file: %@", plist);

[mySong setTrackID: [plist valueForKey:@"Track ID"]];
John Franklin
It would work for one Song i think. But there are thousands of songs in this xml, will I be able to make all the song-objects from single plist if they have same keys? I'm new to code, yeah :)
Yuri
@Yuri: NSArray also has an `arrayWithContentsOfFile:` method. You only need a valid plist with an `<array>` as its root element.
Can Berk Güder
OK, I've RTFM-ed a bit and worked it out. Thanks.
Yuri