Convert between JavaScript objects and XML strings.
With npm:
$ npm install xmlifyjs
or just download the file and paste it into your project
const XML = require('xmlify');
var obj = {
item: {
foo: 'bar',
test: {
hello: "world"
}
}
};
var xml = XML.stringify(obj);
results in
<item>
<foo>bar</foo>
<test>
<hello>world</hello>
</test>
</item>
- object A JavaScript Object, to be converted. Should not contain XML reserved characters.
- (optional) indentation The string at the beginning of each line.
- (optional) linebreak The string at the end of each line.
Example:
var xml = XML.stringify(obj,"","");
results in
<item><foo>bar</foo><test><hello>world</hello></test></item>
const XML = require('xmlify');
var text = "<item><foo>bar</foo><test><hello>world</hello></test></item>"
var xml = XML.parse(text);
results in
Object
item:
foo: "bar"
test:
hello: "world"
- string A valid XML string.
- parse() can't read self-closing tags
- parse() can't read tags which have no content inside
- add support for attributes
- add support for js arrays
MIT © Daniel Breiner