Editing .plist files - are single quotes allowed as strings?
Asked Answered
P

3

7

In particular, I'm editing the AutoCompletion.plist file for CSSEdit (if that even matters).

My question is, are there any characters withing the STRING elements that need to be escaped? spaces? quotes?

EDIT: Just to be clear, I'm not using CSSEdit to edit the file - rather the file is part of the CSSEdit package. I'm using TextMate to edit the file (although "Property List Editor.app" is another option) and it is in XML format. Here's a snippet from the AutoCompletion.plist file:

<?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>font-family</key>
<array>
    <string>Arial</string>
    <string>Helvetica</string>
    <string>Georgia</string>
    <string>serif</string>
    <string>sans-serif</string>
    <string>cursive</string>
    etc...

I'd like to add STRINGs with spaces and single quotes such as:

<string>Georgia, Times, 'Times New Roman', serif</string>

But CSSEdit goes haywire when I edit the file as such

Predictor answered 2/11, 2008 at 5:26 Comment(0)
R
19

If you're editing an XML plist using a text editor of some sort, you'll need to escape characters just like in any XML. The basic characters to watch out for are:

< (less than), escaped as &lt;

> (greater than), escaped as &gt;

& (ampersand), escaped as &amp;

' (apostrophe), escaped as &apos;

" (quote mark), escaped as &quot;

So in your example, you would want

<string>Georgia, Times, &apos;Times New Roman&apos;, serif</string>

You can also use a tool such as Apple's Property List Editor, which is included with their free Xcode developer tools, or a third party product like PlistEdit Pro, both of which will take care of all the character escaping for you.

Redhot answered 2/11, 2008 at 18:16 Comment(1)
Thanks, Brian. That's technically what I was looking for.Predictor
F
2

You can use plutil to check the syntax of your plists. (Note that this won't validate whether the application will understand what you've done to its plist...)

Foresight answered 2/11, 2008 at 18:36 Comment(1)
I think the problem must be that CSSEdit requires the plist to not have spaces or quotes.Predictor
I
0

There are 3 types of plists, and the escaping rules depend on type you are working with. The most common form are XML plists, which do require certain things to be escaped. In general you can use XML escaping rules within the string elements. If you are working with older NextStep style plists I believe much less needs to be escaped, but I would need to look up the details to be certain of what the rules are. The third type are binary, I am pretty confident you are not editing those with CSSEdit.

Incongruous answered 2/11, 2008 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.