function build(obj, opts) { var XMLHDR = { version: '1.0', encoding: 'UTF-8' }; var XMLDTD = { pubid: '-//Apple//DTD PLIST 1.0//EN', sysid: 'http://www.apple.com/DTDs/PropertyList-1.0.dtd' }; var doc = xmlbuilder.create('plist'); doc.dec(XMLHDR.version, XMLHDR.encoding, XMLHDR.standalone); doc.dtd(XMLDTD.pubid, XMLDTD.sysid); doc.att('version', '1.0'); walk_obj(obj, doc); if (!opts) opts = {}; // default `pretty` to `true` opts.pretty = opts.pretty !== false; return doc.end(opts); }
...
"bundle-identifier": "com.company.app",
"bundle-version": "0.1.1",
"kind": "software",
"title": "AppName"
}
];
console.log(plist.build(json));
// <?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"
;>
// <plist version="1.0">
// <key>metadata</key>
// <dict>
// <key>bundle-identifier</key>
...
function parse(xml) { var doc = new DOMParser().parseFromString(xml); if (doc.documentElement.nodeName !== 'plist') { throw new Error('malformed document. First element should be <plist>'); } var plist = parsePlistXML(doc.documentElement); // the root <plist> node gets interpreted as an Array, // so pull out the inner data first if (plist.length == 1) plist = plist[0]; return plist; }
...
Then `require()` the _plist_ module in your file:
``` js
var plist = require('plist');
// now use the `parse()` and `build()` functions
var val = plist.parse('<plist><string>Hello World!</string
></plist>');
console.log(val); // "Hello World!"
```
### Browser
Include the `dist/plist.js` in a `<script>` tag in your HTML file:
...
function parse(xml) { var doc = new DOMParser().parseFromString(xml); if (doc.documentElement.nodeName !== 'plist') { throw new Error('malformed document. First element should be <plist>'); } var plist = parsePlistXML(doc.documentElement); // the root <plist> node gets interpreted as an Array, // so pull out the inner data first if (plist.length == 1) plist = plist[0]; return plist; }
...
Then `require()` the _plist_ module in your file:
``` js
var plist = require('plist');
// now use the `parse()` and `build()` functions
var val = plist.parse('<plist><string>Hello World!</string
></plist>');
console.log(val); // "Hello World!"
```
### Browser
Include the `dist/plist.js` in a `<script>` tag in your HTML file:
...