Thursday, November 29, 2012

Plist File Parsing Using Java

No comments:
Plist File Parsing Using Java

Below example illustrates , how to iterate over a plist file Nodes using apache's   XMLPropertyListConfiguration

  public void infoPlistConversion(String plistPath) throws Exception {
        XMLPropertyListConfiguration conf = new XMLPropertyListConfiguration(plistPath);
        System.out.println("root node children size => "+ conf.getRootNode().getChildrenCount());
        System.out.println("conf root => " + conf.getRootNode().getChild(0).getName());
        System.out.println("conf.getRoot().getChild(0).getValue() => " + conf.getRootNode().getChild(0).getValue());
        List children = conf.getRoot().getChildren();
        printChildrenValue(children);
    }
   
    private void printChildrenValue(List children) {
        if (children instanceof List) {
            List<PListNode> configs = (List<PListNode>) children;
            for (PListNode pListNode : configs) {
                // sub nodes
                if (pListNode.getValue() == null && pListNode.getChildrenCount() > 1) {
                    List pListNodeChildren = pListNode.getChildren();
                    System.out.println("-------------------------------------------------");
                    System.out.println("plist Name root => "+ pListNode.getName());
                    printChildrenValue(pListNodeChildren);
                // just print values
                } else {
                    // if it is ConfigParam and elements are not null
                    System.out.println("plist Name => "+ pListNode.getName());
                    System.out.println("plist Value => "+ pListNode.getValue());
                }
            }
        }
    }

--
Thank you.


Regards,
Kaleeswaran.S

Read More