This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

xmlifyjs

1.0.0-0 • Public • Published

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

Package Sidebar

Install

npm i xmlifyjs

Weekly Downloads

0

Version

1.0.0-0

License

MIT

Unpacked Size

5.99 kB

Total Files

3

Last publish

Collaborators

  • danielbreiner