Jump to content
Sign in to follow this  

help with _XMLDomWrapper.au3 and itunes xml

Recommended Posts


How would I go use _XMLDomWrapper to get what is located in the string of both of these keys below.

I also want to create an array of all of the Persistent IDs. I currently do not have any starting code so I would appreciate any help I get.

<key>Library Persistent ID</key><string>57BD4AFD579DEB32</string>
<key>Persistent ID</key><string>CCB550C029637502</string>

Sample iTunes XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <key>Major Version</key><integer>1</integer>
    <key>Minor Version</key><integer>1</integer>
    <key>Application Version</key><string>7.6.2</string>
    <key>Show Content Ratings</key><true/>
    <key>Music Folder</key><string>{PATH TO FOLDER}</string>
    <key>Library Persistent ID</key><string>57BD4AFD579DEB32</string>
            <key>Track ID</key><integer>80</integer>
            <key>Name</key><string>In Our Talons</string>
            <key>Album Artist</key><string>Bowerbirds</string>
            <key>Album</key><string>Hymns for a Dark Horse</string>
            <key>Kind</key><string>Protected AAC audio file</string>
            <key>Total Time</key><integer>233535</integer>
            <key>Disc Number</key><integer>1</integer>
            <key>Disc Count</key><integer>1</integer>
            <key>Track Number</key><integer>2</integer>
            <key>Track Count</key><integer>10</integer>
            <key>Date Modified</key><date>2008-05-10T00:11:10Z</date>
            <key>Date Added</key><date>2008-05-10T00:10:56Z</date>
            <key>Bit Rate</key><integer>128</integer>
            <key>Sample Rate</key><integer>44100</integer>
            <key>Release Date</key><date>2007-07-10T07:00:00Z</date>
            <key>Artwork Count</key><integer>1</integer>
            <key>Persistent ID</key><string>CCB550C029637502</string>
            <key>Track Type</key><string>File</string>
            <key>Location</key><string>{PATH TO SONG}</string>
            <key>File Folder Count</key><integer>4</integer>
            <key>Library Folder Count</key><integer>1</integer>

Share this post

Link to post
Share on other sites

This one is very tricky. Apple uses an awful format for this, it basically takes all of the usefulness out of xml.

#include "_XMLDomWrapper.au3"

$oXMLFile = _XMLFileOpen("itunes.xml")
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Parse Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)

;Retrieve first 'Library Persistent ID' value
$result = _GetFirstValue("/plist/dict/key[.='Library Persistent ID']/following-sibling::*[1]")
ConsoleWrite("Library Persistent ID: " & $result & @CRLF)

;Retrieve array of all 'Persistent ID' values (count is in element zero)
$result = _XMLGetValue("/plist/dict/dict/dict/key[.='Persistent ID']/following-sibling::*[1]")
If IsArray($result) Then
    For $X = 0 to Ubound($result)-1
        ConsoleWrite("["&$X&"]: " & $result[$X] & @CRLF)
    ConsoleWrite("NOT AN ARRAY" & @CRLF)

;Get the first real value returned from the _XMLGetValue() return array. REQUIRED
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
        Return SetError(1,3,0)
Edited by weaponx

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.