ghoetker
ghoetker

Reputation: 161

Plist/XML parsing in Racket

Hoping for help with something well beyond my experience. I have the following plist. The information I wish to extract is about a quarter of the way down, "A/Amemiya-1984-Tobit-00.pdf". Searching the Racket documents revealed xml/plist. However, because I've not worked with parsing XML or plists before, I am stuck. If anyone could at least get me started, I would really appreciate it. Complete solutions also very welcome. Thank you very much.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>$archiver</key>
    <string>NSKeyedArchiver</string>
    <key>$objects</key>
    <array>
        <string>$null</string>
        <dict>
            <key>$class</key>
            <dict>
                <key>CF$UID</key>
                <integer>7</integer>
            </dict>
            <key>NS.keys</key>
            <array>
                <dict>
                    <key>CF$UID</key>
                    <integer>2</integer>
                </dict>
                <dict>
                    <key>CF$UID</key>
                    <integer>3</integer>
                </dict>
            </array>
            <key>NS.objects</key>
            <array>
                <dict>
                    <key>CF$UID</key>
                    <integer>4</integer>
                </dict>
                <dict>
                    <key>CF$UID</key>
                    <integer>5</integer>
                </dict>
            </array>
        </dict>
        <string>relativePath</string>
        <string>aliasData</string>
        <string>A/Amemiya-1984-Tobit-00.pdf</string>
        <dict>
            <key>$class</key>
            <dict>
                <key>CF$UID</key>
                <integer>6</integer>
            </dict>
            <key>NS.data</key>
            <data>
            AAAAAAF8AAIAAAxNYWNpbnRvc2ggSEQAAAAAAAAAAAAAAAAAAAAA
            AAAAQkQAAf////8ZQW1lbWl5YS0xOTg0LVRvYml0LTAwLnBkZgAA
            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////
            /wAAAAAAAAAAAAAAAAABAAMAAAogY3UAAAAAAAAAAAAAAAAAAUEA
            AAIAOi86VXNlcnM6Z2hvZXRrZXI6QmliRGVza1BhcGVyczpBOkFt
            ZW1peWEtMTk4NC1Ub2JpdC0wMC5wZGYADgA0ABkAQQBtAGUAbQBp
            AHkAYQAtADEAOQA4ADQALQBUAG8AYgBpAHQALQAwADAALgBwAGQA
            ZgAPABoADABNAGEAYwBpAG4AdABvAHMAaAAgAEgARAASADhVc2Vy
            cy9naG9ldGtlci9CaWJEZXNrUGFwZXJzL0EvQW1lbWl5YS0xOTg0
            LVRvYml0LTAwLnBkZgATAAEvAAAVAAIAD///AAA=
            </data>
        </dict>
        <dict>
            <key>$classes</key>
            <array>
                <string>NSMutableData</string>
                <string>NSData</string>
                <string>NSObject</string>
            </array>
            <key>$classname</key>
            <string>NSMutableData</string>
        </dict>
        <dict>
            <key>$classes</key>
            <array>
                <string>NSDictionary</string>
                <string>NSObject</string>
            </array>
            <key>$classname</key>
            <string>NSDictionary</string>
        </dict>
    </array>
    <key>$top</key>
    <dict>
        <key>root</key>
        <dict>
            <key>CF$UID</key>
            <integer>1</integer>
        </dict>
    </dict>
    <key>$version</key>
    <integer>100000</integer>
</dict>
</plist>

Upvotes: 0

Views: 265

Answers (1)

John Clements
John Clements

Reputation: 17233

I'm very unsure, but I'm going to take a stab at what I think you mean: This file contains archived data, and you want to decode the 'data' block. Is that right?

If so, I'm sorry to report that this problem really has nothing to do with plists. Specifically, the plist format is a way of serializing structured data into a file. When you use a plist decoder, it's going to tell you that there's a dictionary where the key '$archiver' is associated with the string 'NSKeyed Archiver', and the string '$objects' is associated with an array containing a string and a dictionary ... etc., until you get down to the part you're interested in, where you'll learn that the key 'NS.Data' is associated with the data

" AAAAAAF8AAIAAAxNYWNpbnRvc2ggSEQAAAAAAAAAAAAAAAAAAAAA AAAAQkQAAf////8ZQW1lbWl5YS0xOTg0LVRvYml0LTAwLnBkZgAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//// /wAAAAAAAAAAAAAAAAABAAMAAAogY3UAAAAAAAAAAAAAAAAAAUEA AAIAOi86VXNlcnM6Z2hvZXRrZXI6QmliRGVza1BhcGVyczpBOkFt ZW1peWEtMTk4NC1Ub2JpdC0wMC5wZGYADgA0ABkAQQBtAGUAbQBp AHkAYQAtADEAOQA4ADQALQBUAG8AYgBpAHQALQAwADAALgBwAGQA ZgAPABoADABNAGEAYwBpAG4AdABvAHMAaAAgAEgARAASADhVc2Vy cy9naG9ldGtlci9CaWJEZXNrUGFwZXJzL0EvQW1lbWl5YS0xOTg0 LVRvYml0LTAwLnBkZgATAAEvAAAVAAIAD///AAA= "

... which you kind of already knew. That is, the plist format describes the structure, but doesn't specify the meaning of these strings.

Now, with that said, it sure looks like that string is base64-encoded. Let's try decoding it with base64...

... Yep, it looks like it's base64 encoded. It comes out as

"| Macintosh HDBD????Amemiya-1984-Tobit-00.pdf???? cuA:/:Users:ghoetker:BibDeskPapers:A:Amemiya-1984-Tobit-00.pdf4Amemiya-1984-Tobit-00.pdf Macintosh HD8Users/ghoetker/BibDeskPapers/A/Amemiya-1984-Tobit-00.pdf/??% "

Does this answer your question?

Upvotes: 1

Related Questions