Editing root.plist as source code results in corrupted plist

笑着哭i 提交于 2019-12-25 02:18:26

问题


I am just starting to work with preference files and I started having problems immediately when editing the root.plist in my settings bundle. My XCode 4 crashes every time I add a property to the plist while editing it as a property list. So I thought I would simply edit as source code. It seems to be a lot easier.

But when I run the program, the root.plist is not being read. (It was working fine with a settings bundle from a demo program. I'm using InAppSettingsKit.) I looked at the root.plist in the source code editor and it looks right. I tried to look at it as a property list and I get an error that says the plist is corrupted.

Here is the contents of my plist. Can someone tell me what is wrong with it?

<?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>PreferenceSpecifiers</key>
    <array>
<!-- Databases -->
        <dict>
            <key>Title</key>                <string>Databases</string>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>db0</string>
            <key>Key</key>                  <string>db0_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>db1</string>
            <key>Key</key>                  <string>db1_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Sharing Actions -->
        <dict>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
            <key>Title</key>                <string>Sharing Actions</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Facebook</string>
            <key>Key</key>                  <string>facebook_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Twitter</string>
            <key>Key</key>                  <string>twitter_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Email</string>
            <key>Key</key>                  <string>email_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>BlogSpot</string>
            <key>Key</key>                  <string>blogspot_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Automatic Email Enable -->
        <dict>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
            <key>Title</key>                <string>Automatic Emailing</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Always Send to Email</string>
            <key>Key</key>                  <string>autoblogspot_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Calendar -->
        <dict>
            <key>Type</key>                 <string>PSRadioGroupSpecifier</string>
            <key>Title</key>                <string>First Day of the Week</string>
            <key>Key</key>                  <string>firstDayOfTheWeek_preference</string>
            <key>Values</key>
                <array>
                    <integer>0</integer>
                    <integer>1</integer>
                    <integer>2</integer>
                    <integer>3</integer>
                    <integer>4</integer>
                    <integer>5</integer>
                    <integer>6</integer>
                </array>
            <key>Titles</key>
                <array>
                    <string>Sunday</string>
                    <string>Monday</string>
                    <string>Tuesday</string>
                    <string>Wednesday</string>
                    <string>Thursday</string>
                    <string>Friday</string>
                    <string>Saturday</string>
                </array>
        </dict>
        <dict>
            <key>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

回答1:


At the very end of the plist you have a dangling key and dict tag.

Lines #90 and #91.

        </dict>
        <dict>
            <key>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

Should be something like:

        </dict>
        <dict />
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

or

        </dict>
        <dict>
            <key>key</key><string>string</string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

I found this out using TextMate. Bundles -> Property List -> Validate Syntax. Doesn't tell you the exact problem, but gets you to the area.

You can also get a line # to look at by trying to open the plist in the Property List Editor app (/Developer/Applications/Utilities/Property List Editor.app)

Plists are XML, so any XML validator will find major problems in your syntax. Rule of thumb, though, is for every tag you need a close tag. For every key you need a value. Empty tags should be <tag /> not <tag></tag>.



来源:https://stackoverflow.com/questions/7787525/editing-root-plist-as-source-code-results-in-corrupted-plist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!