Comparing version 0.2.2 to 0.2.3
@@ -235,2 +235,21 @@ // Generated by CoffeeScript 1.4.0 | ||
exports.parseString = function(str, a, b) { | ||
var cb, options, parser; | ||
if (b != null) { | ||
if (typeof b === 'function') { | ||
cb = b; | ||
} | ||
if (typeof a === 'object') { | ||
options = a; | ||
} | ||
} else { | ||
if (typeof a === 'function') { | ||
cb = a; | ||
} | ||
options = {}; | ||
} | ||
parser = new exports.Parser(options); | ||
return parser.parseString(str, cb); | ||
}; | ||
}).call(this); |
@@ -6,3 +6,3 @@ { | ||
"homepage" : "https://github.com/Leonidas-from-XIV/node-xml2js", | ||
"version" : "0.2.2", | ||
"version" : "0.2.3", | ||
"author" : "Marek Kubica <marek@xivilization.net> (http://xivilization.net)", | ||
@@ -22,3 +22,4 @@ "contributors" : [ | ||
"Raoul Millais (https://github.com/raoulmillais)", | ||
"Salsita Software (http://www.salsitasoft.com/)" | ||
"Salsita Software (http://www.salsitasoft.com/)", | ||
"Mike Schilling <mike@emotive.com> (http://www.emotive.com/)" | ||
], | ||
@@ -29,2 +30,5 @@ "main" : "./lib/xml2js", | ||
}, | ||
"scripts" : { | ||
"test": "zap" | ||
}, | ||
"repository" : { | ||
@@ -39,5 +43,5 @@ "type" : "git", | ||
"coffee-script" : ">=1.0.1", | ||
"zap" : ">=0.2.4-3", | ||
"zap" : ">=0.2.5", | ||
"docco" : ">=0.3.0" | ||
} | ||
} |
100
README.md
@@ -26,12 +26,42 @@ node-xml2js | ||
This will have to do, unless you're looking for some fancy extensive | ||
documentation. If you're looking for every single option and usage, see the | ||
unit tests. | ||
No extensive tutorials required because you are a smart developer! The task of | ||
parsing XML should be an easy one, so let's make it so! Here's some examples. | ||
Shoot-and-forget usage | ||
---------------------- | ||
You want to parse XML as simple and easy as possible? It's dangerous to go | ||
alone, take this: | ||
```javascript | ||
var parseString = require('xml2js').parseString; | ||
var xml = "<root>Hello xml2js!</root>" | ||
parseString(xml, function (err, result) { | ||
console.dir(result); | ||
}); | ||
``` | ||
Can't get easier than this, right? This works starting with `xml2js` 0.2.3. | ||
With CoffeeScript it looks like this: | ||
```coffeescript | ||
parseString = require('xml2js').parseString; | ||
xml = "<root>Hello xml2js!</root>" | ||
parseString xml, (err, result) -> | ||
console.dir result | ||
``` | ||
If you need some special options, fear not, `xml2js` supports a number of | ||
options (see below), you can specify these as second argument: | ||
```javascript | ||
parseString(xml, {trim: true}, function (err, result) { | ||
}); | ||
``` | ||
Simple as pie usage | ||
------------------- | ||
The simplest way to use it, is to use the optional callback interface added in | ||
0.1.11. That's right, if you have been using xml-simple or a home-grown | ||
wrapper, this is for you: | ||
That's right, if you have been using xml-simple or a home-grown | ||
wrapper, this is was added in 0.1.11 just for you: | ||
@@ -51,5 +81,25 @@ ```javascript | ||
Look ma, no event listeners! Alternatively you can still use the traditional | ||
`addListener` variant: | ||
Look ma, no event listeners! | ||
You can also use `xml2js` from | ||
[CoffeeScript](http://jashkenas.github.com/coffee-script/), further reducing | ||
the clutter: | ||
```coffeescript | ||
fs = require 'fs', | ||
xml2js = require 'xml2js' | ||
parser = new xml2js.Parser() | ||
fs.readFile __dirname + '/foo.xml', (err, data) -> | ||
parser.parseString data, (err, result) -> | ||
console.dir result | ||
console.log 'Done.' | ||
``` | ||
"Traditional" usage | ||
------------------- | ||
Alternatively you can still use the traditional `addListener` variant that was | ||
supported since forever: | ||
```javascript | ||
@@ -69,17 +119,10 @@ var fs = require('fs'), | ||
You can also use xml2js from | ||
[CoffeeScript](http://jashkenas.github.com/coffee-script/), further reducing | ||
the clutter: | ||
If you want to parse multiple files, you have multiple possibilites: | ||
```coffeescript | ||
fs = require 'fs', | ||
xml2js = require 'xml2js' | ||
* You can create one `xml2js.Parser` per file. That's the recommended one | ||
and is promised to always *just work*. | ||
* You can call `reset()` on your parser object. | ||
* You can hope everything goes well anyway. This behaviour is not | ||
guaranteed work always, if ever. Use option #1 if possible. Thanks! | ||
parser = new xml2js.Parser() | ||
fs.readFile __dirname + '/foo.xml', (err, data) -> | ||
parser.parseString data, (err, result) -> | ||
console.dir result | ||
console.log 'Done.' | ||
``` | ||
So you wanna some JSON? | ||
@@ -177,4 +220,13 @@ ----------------------- | ||
The development requirements are handled by npm, you just need to install | ||
them. We also have a number of unit tests, they can be run using `zap` | ||
directly from the project root. | ||
[![Build Status](https://secure.travis-ci.org/Leonidas-from-XIV/node-xml2js.png?branch=master)](https://travis-ci.org/Leonidas-from-XIV/node-xml2js) | ||
The development requirements are handled by npm, you just need to install them. | ||
We also have a number of unit tests, they can be run using `npm test` directly | ||
from the project root. This runs zap to discover all the tests and execute | ||
them. | ||
If you like to contribute, keep in mind that xml2js is written in CoffeeScript, | ||
so don't develop on the JavaScript files that are checked into the repository | ||
for convenience reasons. Also, please write some unit test to check your | ||
behaviour and if it is some user-facing thing, add some documentation to this | ||
README, so people will know it exists. Thanks in advance! |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36744
10
234
229