{ "name": "xml2js", "description": "Simple XML to JavaScript object converter.", "keywords": [ "xml", "json" ], "homepage": "https://github.com/Leonidas-from-XIV/node-xml2js", "version": "0.2.2", "author": { "name": "Marek Kubica", "email": "marek@xivilization.net", "url": "http://xivilization.net" }, "contributors": [ { "name": "maqr", "email": "maqr.lollerskates@gmail.com", "url": "https://github.com/maqr" }, { "name": "Ben Weaver", "url": "http://benweaver.com/" }, { "name": "Jae Kwon", "url": "https://github.com/jaekwon" }, { "name": "Jim Robert" }, { "name": "Ștefan Rusu", "url": "http://www.saltwaterc.eu/" }, { "name": "Carter Cole", "email": "carter.cole@cartercole.com", "url": "http://cartercole.com/" }, { "name": "Kurt Raschke", "email": "kurt@kurtraschke.com", "url": "http://www.kurtraschke.com/" }, { "name": "Contra", "email": "contra@australia.edu", "url": "https://github.com/Contra" }, { "name": "Marcelo Diniz", "email": "marudiniz@gmail.com", "url": "https://github.com/mdiniz" }, { "name": "Michael Hart", "url": "https://github.com/mhart" }, { "name": "Zachary Scott", "email": "zachary@zacharyscott.net", "url": "http://zacharyscott.net/" }, { "name": "Raoul Millais", "url": "https://github.com/raoulmillais" }, { "name": "Salsita Software", "url": "http://www.salsitasoft.com/" } ], "main": "./lib/xml2js", "directories": { "lib": "./lib" }, "repository": { "type": "git", "url": "https://github.com/Leonidas-from-XIV/node-xml2js.git" }, "dependencies": { "sax": ">=0.4.2" }, "devDependencies": { "coffee-script": ">=1.0.1", "zap": ">=0.2.4-3", "docco": ">=0.3.0" }, "readme": "node-xml2js\n===========\n\nEver had the urge to parse XML? And wanted to access the data in some sane,\neasy way? Don't want to compile a C parser, for whatever reason? Then xml2js is\nwhat you're looking for!\n\nDescription\n===========\n\nSimple XML to JavaScript object converter. Uses\n[sax-js](https://github.com/isaacs/sax-js/).\n\nNote: If you're looking for a full DOM parser, you probably want\n[JSDom](https://github.com/tmpvar/jsdom).\n\nInstallation\n============\n\nSimplest way to install `xml2js` is to use [npm](http://npmjs.org), just `npm\ninstall xml2js` which will download xml2js and all dependencies.\n\nUsage\n=====\n\nThis will have to do, unless you're looking for some fancy extensive\ndocumentation. If you're looking for every single option and usage, see the\nunit tests.\n\nSimple as pie usage\n-------------------\n\nThe simplest way to use it, is to use the optional callback interface added in\n0.1.11. That's right, if you have been using xml-simple or a home-grown\nwrapper, this is for you:\n\n```javascript\nvar fs = require('fs'),\n xml2js = require('xml2js');\n\nvar parser = new xml2js.Parser();\nfs.readFile(__dirname + '/foo.xml', function(err, data) {\n parser.parseString(data, function (err, result) {\n console.dir(result);\n console.log('Done');\n });\n});\n```\n\nLook ma, no event listeners! Alternatively you can still use the traditional\n`addListener` variant:\n\n```javascript\nvar fs = require('fs'),\n xml2js = require('xml2js');\n\nvar parser = new xml2js.Parser();\nparser.addListener('end', function(result) {\n console.dir(result);\n console.log('Done.');\n});\nfs.readFile(__dirname + '/foo.xml', function(err, data) {\n parser.parseString(data);\n});\n```\n\nYou can also use xml2js from\n[CoffeeScript](http://jashkenas.github.com/coffee-script/), further reducing\nthe clutter:\n\n```coffeescript\nfs = require 'fs',\nxml2js = require 'xml2js'\n\nparser = new xml2js.Parser()\nfs.readFile __dirname + '/foo.xml', (err, data) ->\n parser.parseString data, (err, result) ->\n console.dir result\n console.log 'Done.'\n```\n\nSo you wanna some JSON?\n-----------------------\n\nJust wrap the `result` object in a call to `JSON.stringify` like this\n`JSON.stringify(result)`. You get a string containing the JSON representation\nof the parsed object that you can feed to JSON-hungry consumers.\n\nDisplaying results\n------------------\n\nYou might wonder why, using `console.dir` or `console.log` the output at some\nlevel is only `[Object]`. Don't worry, this is not because xml2js got lazy.\nThat's because Node uses `util.inspect` to convert the object into strings and\nthat function stops after `depth=2` which is a bit low for most XML.\n\nTo display the whole deal, you can use `console.log(util.inspect(result, false,\nnull))`, which displays the whole result.\n\nSo much for that, but what if you use\n[eyes](https://github.com/cloudhead/eyes.js) for nice colored output and it\ntruncates the output with `…`? Don't fear, there's also a solution for that,\nyou just need to increase the `maxLength` limit by creating a custom inspector\n`var inspect = require('eyes').inspector({maxLength: false})` and then you can\neasily `inspect(result)`.\n\nOptions\n=======\n\nApart from the default settings, there is a number of options that can be\nspecified for the parser. Options are specified by ``new Parser({optionName:\nvalue})``. Possible options are:\n\n * `attrkey` (default: `$`): Prefix that is used to access the attributes.\n Version 0.1 default was `@`.\n * `charkey` (default: `_`): Prefix that is used to access the character\n content. Version 0.1 default was `#`.\n * `explicitCharkey` (default: `false`)\n * `trim` (default: `false`): Trim the whitespace at the beginning and end of\n text nodes.\n * `normalizeTags` (default: `false`): Normalize all tag names to lowercase.\n * `normalize` (default: `false`): Trim whitespaces inside text nodes.\n * `explicitRoot` (default: `true`): Set this if you want to get the root\n node in the resulting object.\n * `emptyTag` (default: `undefined`): what will the value of empty nodes be.\n Default is `{}`.\n * `explicitArray` (default: `true`): Always put child nodes in an array if\n true; otherwise an array is created only if there is more than one.\n * `ignoreAttrs` (default: `false`): Ignore all XML attributes and only create\n text nodes.\n * `mergeAttrs` (default: `false`): Merge attributes and child elements as\n properties of the parent, instead of keying attributes off a child\n attribute object. This option is ignored if `ignoreAttrs` is `false`.\n * `validator` (default `null`): You can specify a callable that validates\n the resulting structure somehow, however you want. See unit tests\n for an example.\n * `xmlns` (default `false`): Give each element a field usually called '$ns'\n (the first character is the same as attrkey) that contains its local name\n and namespace URI.\n\nUpdating to new version\n=======================\n\nVersion 0.2 changed the default parsing settings, but version 0.1.14 introduced\nthe default settings for version 0.2, so these settings can be tried before the\nmigration.\n\n```javascript\nvar xml2js = require('xml2js');\nvar parser = new xml2js.Parser(xml2js.defaults[\"0.2\"]);\n```\n\nTo get the 0.1 defaults in version 0.2 you can just use\n`xml2js.defaults[\"0.1\"]` in the same place. This provides you with enough time\nto migrate to the saner way of parsing in xml2js 0.2. We try to make the\nmigration as simple and gentle as possible, but some breakage cannot be\navoided.\n\nSo, what exactly did change and why? In 0.2 we changed some defaults to parse\nthe XML in a more universal and sane way. So we disabled `normalize` and `trim`\nso xml2js does not cut out any text content. You can reenable this at will of\ncourse. A more important change is that we return the root tag in the resulting\nJavaScript structure via the `explicitRoot` setting, so you need to access the\nfirst element. This is useful for anybody who wants to know what the root node\nis and preserves more information. The last major change was to enable\n`explicitArray`, so everytime it is possible that one might embed more than one\nsub-tag into a tag, xml2js >= 0.2 returns an array even if the array just\nincludes one element. This is useful when dealing with APIs that return\nvariable amounts of subtags.\n\nRunning tests, development\n==========================\n\nThe development requirements are handled by npm, you just need to install\nthem. We also have a number of unit tests, they can be run using `zap`\ndirectly from the project root.\n", "readmeFilename": "README.md", "_id": "xml2js@0.2.2", "_from": "xml2js" }