编辑 .plist 文件 - 是否允许单引号作为字符串?

发布于 2024-07-08 18:28:50 字数 974 浏览 9 评论 0原文

特别是,我正在编辑 CSSEdit 的 AutoCompletion.plist 文件(如果这很重要的话)。

我的问题是, STRING 元素中是否有任何字符需要转义? 空格? 引号?

编辑: 需要明确的是,我没有使用 CSSEdit 来编辑该文件 - 该文件是 CSSEdit 包的一部分。 我正在使用 TextMate 编辑该文件(尽管“Property List Editor.app”是另一个选项),并且它是 XML 格式。 以下是 AutoCompletion.plist 文件中的片段:

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

我想添加带有空格和单引号的字符串,例如:

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

但是当我这样编辑文件时 CSSEdit 会变得混乱

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人疚 2024-07-15 18:28:50

如果您使用某种文本编辑器编辑 XML plist,则需要像在任何 XML 中一样转义字符。 需要注意的基本字符是:

< (小于),转义为 <

> (大于),转义为 >

& (& 符号),转义为 &

'(撇号),转义为 '

"(引号),转义为 "

因此,在您的示例中,您需要

Georgia, Times, 'Times New Roman', serif

您还可以使用 Apple 的属性列表编辑器等工具,该工具包含在其免费的 Xcode 开发人员中工具,或第三方产品,例如 PlistEdit Pro,这两者都会处理所有的角色都为你而逃。

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 <

> (greater than), escaped as >

& (ampersand), escaped as &

' (apostrophe), escaped as '

" (quote mark), escaped as "

So in your example, you would want

<string>Georgia, Times, 'Times New Roman', 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.

|煩躁 2024-07-15 18:28:50

您可以使用 plutil 来检查 plist 的语法。 (请注意,这不会验证应用程序是否能够理解您对其 plist 所做的操作...)

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

黯淡〆 2024-07-15 18:28:50

plist 有 3 种类型,转义规则取决于您正在使用的类型。 最常见的形式是 XML plist,它确实需要转义某些内容。 一般来说,您可以在字符串元素中使用 XML 转义规则。 如果您正在使用较旧的 NextStep 样式 plist,我相信需要转义的内容要少得多,但我需要查找详细信息以确定规则是什么。 第三种类型是二进制的,我非常有信心您不会使用 CSSEdit 编辑它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文