However, js2xmlparser is capable of parsing any object, including native
RegExp, by taking advantage of each
toString function or, if this function does not exist, the
js2xmlparser also has support for the new
Set objects introduced in
ECMAScript 2015, treating them as JSON-type objects and arrays respectively.
Maps is necessary to generate XML with elements in a specific
order, since JSON-type objects do not guarantee insertion order.
Map keys are
always converted to strings using the method described above.
js2xmlparser also supports a number of constructs unique to XML:
js2xmlparser can also pretty-print the XML it outputs.
The easiest way to install js2xmlparser is using npm:
npm install js2xmlparser
You can also build js2xmlparser from source using gulp:
git clonenpm installgulp
You'll need to install gulp first if you don't have it:
npm install -g gulp
You can then copy the folder into your node_modules directory.
default target will build the production variant of js2xmlparser, run all
tests, and build the documentation.
You can build the production variant without running tests using the target
prod. You can also build the development version using the target
the moment, the only difference between the two is that the development version
includes source maps.
The documentation for the current version is available here.
You can also build the documentation using gulp:
The following example illustrates the basic usage of js2xmlparser:
var js2xmlparser = ;var obj ="firstName": "John""lastName": "Smith""dateOfBirth": 1964 7 26"address":"@":"type": "home""streetAddress": "3212 22nd St""city": "Chicago""state": "Illinois""zip": 10000"phone":"@":"type": "home""#": "123-555-4567""@":"type": "cell""#": "890-555-1234""@":"type": "work""#": "567-555-8901""email": "email@example.com";console;
This example produces the following XML:
JohnSmithWed Aug 26 1964 00:00:00 GMT-0400 (Eastern Summer Time)3212 22nd StChicagoIllinois10000123firstname.lastname@example.org
Additional examples can be found in examples/example.js.
js2xmlparser includes a set of tests to verify core functionality. You can run the tests using gulp:
test target builds the production variant of js2xmlparser before running
the tests. The
test-prod target does the same thing, while the
target builds the development variant first instead.
js2xmlparser is licensed under the Apache License 2.0. Please see the LICENSE.md file for more information.