1

I have an XML file that I am trying to parse and store as objects so that I can persist them.

<key>Playlists</key>
<array>
    <dict>
        <key>Name</key><string>Library</string>
        <key>Master</key><true/>
        <key>Playlist ID</key><integer>1806</integer>
        <key>Playlist Persistent ID</key><string>29E12A03204E0722</string>
        <key>Visible</key><false/>
        <key>All Items</key><true/>
        <key>Playlist Items</key>
        <array>
            <dict>
                <key>Track ID</key><integer>1234</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1282</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1694</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1558</integer>
            </dict>
       </array>
    </dict>
    <dict>
        <key>Name</key><string>Music</string>
        <key>Playlist ID</key><integer>2687</integer>
        <key>Playlist Persistent ID</key><string>29E12A03204E072C</string>
        <key>Distinguished Kind</key><integer>4</integer>
        <key>Music</key><true/>
        <key>All Items</key><true/>
        <key>Playlist Items</key>
        <array>
            <dict>
                <key>Track ID</key><integer>1234</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1282</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1694</integer>
            </dict>
            <dict>
                <key>Track ID</key><integer>1558</integer>
            </dict>
       </array>
    </dict>

I'm having trouble accessing the second array. It keeps displaying track Id's from the first array in every playlist.

It is doing this for all the playlists I am trying to display.

Could anyone help me with this?

1

1 Answer 1

0

Change

NodeList tList = (NodeList)x.evaluate("/plist/dict/array/dict/array/dict", root, XPathConstants.NODESET);

to

NodeList tList = (NodeList)x.evaluate("array/dict", dict, XPathConstants.NODESET);
Sign up to request clarification or add additional context in comments.

1 Comment

That doesn't seem to work. Still showing the same numbers in every playlist.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.