README
XMLify
Convert between JavaScript objects and XML strings.
Installation
With npm:
$ npm install xmlifyjs
or just download the file and paste it into your project
Usage
stringify(object, indentation?, linebreak?)
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>
parameters
- 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>
parse(string)
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"
parameters
- string A valid XML string.
known limitations
- parse() can't read self-closing tags
- parse() can't read tags which have no content inside
future plans
- add support for attributes
- add support for js arrays
License
MIT © Daniel Breiner