Monday, March 11, 2013
XMLPropertyListConfiguration / Plist Parser example
XMLPropertyListConfiguration / Plist Parser example
XMLPropertyListConfiguration is having a fantastic API to work with plist files. But there is no much example for this library. After some googling and library analysis, it came to know that it is very very easy to parse the files !. Here is the example.
@Test
public void test() {
try {
String plistFile = "/Users/plistFile/info.plist";
XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
HashMap life = new HashMap();
life.put("Home", "home.png");
life.put("Office", "browse.png");
life.put("School", "mycart.png");
life.put("College", "offers.png");
plist.addProperty("Life", life);
HashMap phones = new HashMap();
phones.put("Nokia", "8000");
phones.put("Samsung", "4000");
List<String> imagesArray = new ArrayList<String>();
imagesArray.add("icon1.png");
imagesArray.add("icon2.png");
imagesArray.add("icon3.png");
phones.put("PhoneIcons", imagesArray);
plist.addProperty("Phones", phones);
List<String> imagesArray1 = new ArrayList<String>();
imagesArray1.add("icon1.png");
imagesArray1.add("icon2.png");
imagesArray1.add("icon3.png");
Map dashBoard = new HashMap();
dashBoard.put("imgArray", imagesArray1);
plist.addProperty("ImageArrayBoard", dashBoard);
plist.addProperty("ImageArray.innnerLevelTag", "IamInnerLevelTag");
plist.save(plistFile);
System.out.println("File saved .... ");
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
}
Thats All, Happy Coding :)
Ref : http://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.html
Related Posts
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment