Since XML is a data-interchange format, js2xmlparser is designed primarily for
JSON-type objects, arrays and primitive data types, like many of the other
However, js2xmlparser is capable of parsing any object, including native
object's toString function or, if this function does not exist, the String
js2xmlparser also has support for the new Map and Set objects introduced in
ECMAScript 2015, treating them as JSON-type objects and arrays respectively.
Support for 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:
attributes (through an attribute property in objects)
mixed content (through value properties in objects)
multiple elements with the same name (through arrays)
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:
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.
The 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 dev. At
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:
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:
The test target builds the production variant of js2xmlparser before running
the tests. The test-prod target does the same thing, while the test-dev
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.