使用程序而不是 Perl 进行文本处理

发布于 2024-08-04 00:02:08 字数 1297 浏览 4 评论 0原文

我有一个如下所示的 .plist 文件:

<plist version="1.0">
<array>
<dict>
    <key>name</key>
    <string>Alabama</string>
    <key>abreviation</key>
    <string>AL</string>
    <key>date</key>
    <string>1819</string>
    <key>population</key>
    <string>4,627,851</string>
    <key>capital</key>
    <string>Montgomery</string>
    <key>largestCity</key>
    <string>Birmingham</string>
</dict>
....
</array>
</plist>

我想向 plist 添加更多信息,例如座右铭和昵称。它们的格式如下:

<nickname>Yellowhammer State</nickname>
<nickname>The Last Frontier</nickname>
<nickname>The Grand Canyon State</nickname>
<nickname>The Natural State</nickname>
<nickname>The Golden State</nickname>
<nickname>The Centennial State</nickname>
<nickname>The Constitution State</nickname>
<nickname>The First State</nickname>
<nickname>The Sunshine State</nickname>

我正在考虑进行一些搜索和替换以添加更多信息。我还可以编写一个 perl 脚本来读取昵称并将其添加到 plist 中。

但是,是否有一个文本处理程序可以让我迭代这些值并将它们插入到正确的位置?我一直在搜索文本处理器/编辑器,但找不到我要找的东西。

I have a .plist file that looks like this:

<plist version="1.0">
<array>
<dict>
    <key>name</key>
    <string>Alabama</string>
    <key>abreviation</key>
    <string>AL</string>
    <key>date</key>
    <string>1819</string>
    <key>population</key>
    <string>4,627,851</string>
    <key>capital</key>
    <string>Montgomery</string>
    <key>largestCity</key>
    <string>Birmingham</string>
</dict>
....
</array>
</plist>

I want to add more information to the plist such as motto and nickname. They are in this format:

<nickname>Yellowhammer State</nickname>
<nickname>The Last Frontier</nickname>
<nickname>The Grand Canyon State</nickname>
<nickname>The Natural State</nickname>
<nickname>The Golden State</nickname>
<nickname>The Centennial State</nickname>
<nickname>The Constitution State</nickname>
<nickname>The First State</nickname>
<nickname>The Sunshine State</nickname>

I am considering doing some search and replace to add more information. I could also write a perl script to read the nicknames and add them into the plist.

But, is there a text processing program that would allow me to iterate over the values and insert them in the correct spot? I have been searching through text processors/editors and cannot find what I am looking for.

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

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

发布评论

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

评论(2

尹雨沫 2024-08-11 00:02:08

这看起来像是 XSLT 的工作:Mac 或 Linux 上的 xsltproc。
(或 SAXON,支持 XSLT 2.0 )

[您没有提到第二个文件中的昵称如何匹配
第一个文件中的值:它们的顺序是否匹配? ]

That looks like a job for XSLT: xsltproc on the Mac or Linux.
( or SAXON, which supports XSLT 2.0 )

[ You don't mention how the nicknames in the 2nd file match up
to values in the first file: are they in matching sequence ? ]

独自唱情﹋歌 2024-08-11 00:02:08

首先,我建议创建 plist 1.1,将您的名称值对视为相关实体,例如:

<key name="capital" value="Montgomery" />

<key>capital <value>Montgomery</value></key>

在我看来,让它们按照您现有的方式分开将使您将来想要进行的任何处理变得更加困难。

您需要昵称附近有更多元信息,以便与正确的状态关联,除非您希望每次插入时都收到提示。像这样的昵称

<nickname state="AL">Yellowhammer State</nickname>

将为您提供轻松地将数据以任何语言插入到正确位置所需的一切。

First, I would recommend creating plist 1.1 that treats your name value pairs like the related entities that they are, for example:

<key name="capital" value="Montgomery" />

or

<key>capital <value>Montgomery</value></key>

It seems to me that having them separate the way you have would make any future processing you want to do harder.

You need more meta information near the nickname for you to make the association to the correct state unless you want to be prompted for each insertion. making the nicknames like

<nickname state="AL">Yellowhammer State</nickname>

would give you all you need to easily insert your data in the proper spot in any language.

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