Giter Club home page Giter Club logo

node-easyxml's Introduction

Easy XML

Highly configurable Object to XML converter for Node.

Installation

$ npm install easyxml

Usage

var EasyXml = require('easyxml');

var serializer = new EasyXml({
    singularizeChildren: true,
    allowAttributes: true,
    rootElement: 'response',
    dateFormat: 'ISO',
    indent: 2,
    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

  • singularizeChildren: If an array is plural, its children elements will be singular, default: true
  • allowAttributes: String attributes starting with _ will be XML attributes, default: true
  • attributePrefix: Prefix to look for when creating attributes, default: _
  • elementPrefix: If present, element is created if property has this prefix or value is an object, otherwise attribute will be created, default: ``
  • rootElement: A string to wrap around the rendered XML document, default: response
  • rootArray: If the root element is an array, this wraps the XML document. Should be plural, default: items
  • dateFormat: A date format for JS dates, currently accepts ISO, SQL, JS, default: ISO
  • indent: A number representing the spaces to indent children, use 0 for no whitespace, default: 4
  • manifest: Whether or not to add that XML manifest line to the top, default: false
  • unwrappedArrays: Do not render root element of the array (gitchildren names are not singularized), default: false
  • filterNulls: Should nulls and undefines be removed from the rendered XML, default: false
  • decamelize: Should camel case names of elements and attributes be converted for example someAttr -> some-attr, separator is - by default or not empty value of decamelize, default: false
  • decamelizeAttributes: The same as decamelize but only for attributes , default: false
  • decamelizeElements: The same as decamelize but only for elements, default: false

License

This project is licensed under a Dual BSD/GPL license.

node-easyxml's People

Contributors

tlhunter avatar kalisjoshua avatar dweidenfeld avatar patmoore avatar i-e-b avatar dusty avatar cagefox avatar lewellyn avatar

Watchers

Alex avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.