create-xml-ls

0.0.9 • Public • Published

create-xml-ls Build Status

Another JS object to XML converter

Instalation

npm install create-xml-ls

Example

Javascript

createXml(obj[, options])

var createXml = require('create-xml-ls');
 
createXml({
  something: {
    is: 'very',
    ugly: {
      $attr: {
        IMHO: 'it sucks'
      }
      but: 'sometimes we have to live with it'
    }
  }
}, { pretty: true });
/* =>
<?xml version="1.0" encoding="UTF-8"?>
<something>
  <is>very</is>
  <ugly IMHO="it sucks">
    <but>sometimes we have to live with it</but>
  </ugly>
</something>
*/

Indentation is off by default, but can be toggled with options.pretty set to true.

The default attributes key is '$attr', but you can also use a custom one by setting options.attributesKey to the desired key.

createXml({
  something:
    is: {
      attributes: {
        'kind': 'of'
      },
      interesting: 'about this'
    }
}, { pretty: true, attributesKey: 'attributes' );
/* =>
<?xml version="1.0" encoding="UTF-8"?>
<something>
  <is kind="of">
    <interesting>about this</interesting>
  </is>
</something>
*/

There's also support for array properties.

createXml({
  arrayExample: {
    sometimes: [
      'I',
      'had',
      'to',
      'do',
      'this'
    ]
  }
}, { pretty: true });
/* =>
<?xml version="1.0" encoding="UTF-8"?>
<arrayExample>
  <sometimes>I</sometimes>
  <sometimes>had</sometimes>
  <sometimes>to</sometimes>
  <sometimes>do</sometimes>
  <sometimes>this</sometimes>
</arrayExample>
*/}

License

Copyright (c) 2013 Pedro Yamada. Licensed under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i create-xml-ls

Weekly Downloads

10

Version

0.0.9

License

none

Last publish

Collaborators

  • yamadapc