使用程序而不是 Perl 进行文本处理
我有一个如下所示的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像是 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 ? ]
首先,我建议创建 plist 1.1,将您的名称值对视为相关实体,例如:
或
在我看来,让它们按照您现有的方式分开将使您将来想要进行的任何处理变得更加困难。
您需要昵称附近有更多元信息,以便与正确的状态关联,除非您希望每次插入时都收到提示。像这样的昵称
将为您提供轻松地将数据以任何语言插入到正确位置所需的一切。
First, I would recommend creating plist 1.1 that treats your name value pairs like the related entities that they are, for example:
or
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
would give you all you need to easily insert your data in the proper spot in any language.