views:

80

answers:

2

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.

A: 

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.

DaveParillo
Is that format allowed in plists? http://www.cakoose.com/wiki/plist_xml_is_pointless How do you access your values and attributes using cocoa?
Bryan
Sorry - I didn't catch the significance of the plist tag. You're clearly stuck with the schema already defined for plist. I stand by my statement that the nickname tags need something to allow you to associate a nickname with the correct state.you do insert the using any language you're comfy with. Just make sure you use the xml tools already provided - i.e. don't write your own xpath parser, in perl you'd use XML::LibXML or XML::Parser and XML::XSLT.
DaveParillo
+1  A: 

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

Steven D. Majewski
Yes, they are in sequence. I will look at XSLT now.
Bryan