开发者

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?


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.


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.


dd-plist might be helpful.

Serialize native java data structures to property list objects

Deserialize from property list objects to native java data structures

You can also directly convert the contained NSObject objects into native Java objects with the NSObject.toJavaObject() method. Using this method you can avoid working with NSObject instances altogether.

<dependency>
  <groupId>com.googlecode.plist</groupId>
  <artifactId>dd-plist</artifactId>
  <version>1.26</version>
</dependency>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜