NSXMLParser. How to parse KVC-plist-thingamajig-like XML?
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>开发者_StackOverflow中文版;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.
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"]];
精彩评论