Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top