Socket
Socket
Sign inDemoInstall

easyxml

Package Overview
Dependencies
3
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    easyxml

A configurable object to XML converter


Version published
Maintainers
1
Install size
453 kB
Created

Readme

Source

Easy XML

Highly configurable Object to XML converter for Node.

Installation

$ npm install easyxml

Usage

var EasyXml = require('easyxml');

var serializer = new EasyXml({
    singularize: true,
    rootElement: 'response',
    dateFormat: 'ISO',
    manifest: true
});

var obj = {
    items: [{
        name: 'one',
        _id: 1
    }, {
        name: 'two',
        _id: 2
    }, {
        name: 'three',
        _id: 3
    }],
    blah: 'http://www.google.com',
    when: new Date(),
    boolz: true,
    nullz: null
};

console.log(serializer.render(obj));

This should output the following XML document:

<?xml version='1.0' encoding='utf-8'?>
<response>
  <items>
    <item id="1">
      <name>one</name>
    </item>
    <item id="2">
      <name>two</name>
    </item>
    <item id="3">
      <name>three</name>
    </item>
  </items>
  <blah>http://www.google.com</blah>
  <when>2012-09-25T18:47:39.485Z</when>
  <boolz>true</boolz>
  <nullz />
</response>

Configuration

Config SettingPurposeDefault
attributePrefixJSON with this prefix will be XML attributes instead of elements'_'
dateFormatA date format for JS dates, currently accepts ISO, SQL, JS'ISO'
filterNullsShould nulls and undefines be removed from the rendered XMLfalse
indentThe number of spaces to indent child elements with2
manifestWhether or not to add that XML manifest line to the topfalse
rootArrayIf the root element is an array, this wraps the XML document'items'
rootElementA string to wrap around the rendered XML document'response'
singularizeIf an array is plural, its children elements will be singulartrue
unwrapArraysIf true will keep array children at parents levelfalse

Migration Guide from 1.x to 2.x

  • singularizeChildren has been renamed singularize
  • allowAttributes has been removed since it was redundant
  • unwrappedArrays has been renamed unwrapArrays
  • Behavior: XML documents now default to 2 spaces instead of 4
  • Behavior: Objects with .toJSON() methods now have that method executed
  • Behavior: When using singularize with a pluralized array of objects they now no longer accidentally nest

License

This project is dually licensed under the BSD-3-Clause / GPL-2.0 licenses.

Keywords

FAQs

Last updated on 05 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc