Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Plist Converted to Java Data Structures

I have a program that is going to be receiving info displayed in it from a .plist on my server. However, I am going to be making this for PC, and I'm using Java to do so. Plist files aren't conventional XML, so common XML parsing libraries don't work. I can't locate any plist specific parsers, so I am lost on how to continue. The way I see it my options are:

a) Locate such a parser for the plist file

b) Make a workaround using a regular XML parser

c) Change the file the program gets its data from (undesirable)

Has anyone else had any experience with plists in languages other than Objective-C?

like image 495
Jumhyn Avatar asked Sep 13 '25 10:09

Jumhyn


2 Answers

As @Jochen Bedersdorfer notes, .plist files are XML with a well-formed DTD. Use plutil to convert them from binary to text form.

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

Addendum: In a comment, you asked

Isn't it text form when I get it?

Not necessarily. Here's some history on the subject.

like image 151
trashgod Avatar answered Sep 16 '25 00:09

trashgod


To remove any confusion:

  1. A plist file can be either in XML or in binary form.
  2. The binary plist is of course not XML.
  3. The XML plist is of course XML. In fact it's a valid XML... try xmllint against an XML plist.
  4. Yes it has slightly unconventional structure. As you say, it's like <dt>title</dt><dd>description</dd>.
  5. You can convert a binary plist to an XML plist using plutil on OS X. Convert it to XML before sending it over the network.
  6. With a regular XML parser you can get key and string. Make a hash containing these pairs. Then you get the string based on the key.
like image 25
Yuji Avatar answered Sep 16 '25 01:09

Yuji