xmlmacosplistcssedit

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


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


Solution

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