views:

853

answers:

3

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"&gt;
<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

A: 

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.

Louis Gerbarg
+3  A: 

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;

' (apostraphe), 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.

Brian Webster
Thanks, Brian. That's technically what I was looking for.
Andy Ford
+1  A: 

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...)

Nicholas Riley
I think the problem must be that CSSEdit requires the plist to not have spaces or quotes.
Andy Ford