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({
    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 Setting Purpose Default
attributePrefix JSON with this prefix will be XML attributes instead of elements '_'
dateFormat A date format for JS dates, currently accepts ISO, SQL, JS 'ISO'
filterNulls Should nulls and undefines be removed from the rendered XML false
indent The number of spaces to indent child elements with 2
manifest Whether or not to add that XML manifest line to the top false
rootArray If the root element is an array, this wraps the XML document 'items'
rootElement A string to wrap around the rendered XML document 'response'
singularize If an array is plural, its children elements will be singular true
unwrapArrays If true will keep array children at parents level false

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.

node-easyxml's People

Contributors

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-easyxml's Issues

Get rid of test fixtures, just have test files

Fixtures are too limiting, they are only appropriate for structures which can be expressed as JSON.

We frequently need to test more complex objects e.g. those with Dates or instances of Moment.js.

Make a bunch of different test files, grouped logically, and remove all fixures.

Ambiguous licences

Would it be possible to specify which versions of BSD and GPL you are using?
BSD exists in at least three flavours:

To which of the following does "GPL" refer?

  • GNU GPL v. 2.0: the FSF does no longer recommend this version; it is not compatible with GNU GPL v. 3.0;
  • GNU GPL v. 3.0: the latest version;
  • GNU LGPL v. 2.1: less strong than GPL; designed to allow linking with non-GPL software (e.g. you can develop LGPL'ed extensions for LibreOffice);
  • GNU AGPL v. 3.0: like LGPL but with a clause that is relevant to software that runs on a server.

I would appreciate it if you could clarify this.

Convert an Array of JSON Objects into XML

Hello, thankyou for this great library.

Currently I am trying to convert an array of JSON objects into XML using node-easyxml.

This is my array I am trying to convert into XML

[{"id":346,"group":222,"content":"new Item","editable":true,"selectable":true,"start":"2019-12-08T17:00:29.608Z","end":"2019-12-08T17:20:29.608Z","className":"default","status":"default","duration":null,"offset":null,"repeat_id":null,"repeat":false,"repeatvalues":null,"preset_id":21,"customer_id":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8","user_id":"099fab15-cdb0-4c67-add7-5532afaddfdd","createdAt":"2019-12-08T11:44:53.678Z","updatedAt":"2019-12-08T11:44:53.678Z","customerId":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8"},{"id":147,"group":20,"content":"new Item","editable":false,"selectable":false,"start":"2019-10-08T20:15:59.000Z","end":"2019-10-08T20:17:04.000Z","className":"grey","status":"done","duration":null,"offset":null,"repeat_id":null,"repeat":false,"repeatvalues":null,"preset_id":4,"customer_id":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8","user_id":"099fab15-cdb0-4c67-add7-5532afaddfdd","createdAt":"2019-10-08T20:15:54.796Z","updatedAt":"2019-10-08T20:17:04.569Z","customerId":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8"},{"id":148,"group":22,"content":"new Item","editable":false,"selectable":false,"start":"2019-10-08T20:16:02.000Z","end":"2019-10-08T20:17:07.000Z","className":"grey","status":"done","duration":null,"offset":null,"repeat_id":null,"repeat":false,"repeatvalues":null,"preset_id":4,"customer_id":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8","user_id":"099fab15-cdb0-4c67-add7-5532afaddfdd","createdAt":"2019-10-08T20:15:57.874Z","updatedAt":"2019-10-08T20:17:07.558Z","customerId":"4f5b1a46-8537-4a07-81b2-810c8be7d0a8"}]

What I get is this.

<?xml version='1.0' encoding='utf-8'?> <items> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> <item>[object Object]</item> </items>

I have also tried to convert a single Object, but then the library says

error: _previousDataValuescontained non_string_attribute

This was related to a Sequelize DataValues issue. They were an object in a object. I am not pretty sure why this error message occured.

If I convert a single object then it seems to work now, but Arrays of Objects seem to be the issue here.

Thankyou

Best Regards

Is this dead?

I made a fork last night to add some functionality I needed and was going to put together a pull request, but I see no activity on what look like valid pull requests as far back as 6 months or more.

The most active fork seems to be https://github.com/AGascoigne/node-easyxml which is published on npm as easyxml-ts. Should I be working against that code base instead? Should we call this fork dead and redirect to that (as quickenloans did to your repo)?

Fix documentation

The existing docs suck, and it's all my fault. Rebuild them from the ground up.

moment() objects not working

Error: _isAMomentObjectcontained non_string_attribute
   at EasyXml.parseChildElement (/Users/username/projects/getrandomdate/node_modules/easyxml/index.js:186:27)
   at EasyXml.parseChildElement (/Users/username/projects/getrandomdate/node_modules/easyxml/index.js:236:22)
   at EasyXml.render (/Users/username/projects/getrandomdate/node_modules/easyxml/index.js:109:10)
   at /Users/username/projects/getrandomdate/server/index.js:72:25
   at Layer.handle [as handle_request] (/Users/username/projects/getrandomdate/node_modules/express/lib/router/layer.js:82:5)
   at next (/Users/username/projects/getrandomdate/node_modules/express/lib/router/route.js:100:13)
   at Route.dispatch (/Users/username/projects/getrandomdate/node_modules/express/lib/router/route.js:81:3)
   at Layer.handle [as handle_request] (/Users/username/projects/getrandomdate/node_modules/express/lib/router/layer.js:82:5)
   at proto.handle.c (/Users/username/projects/getrandomdate/node_modules/express/lib/router/index.js:235:24)
   at param (/Users/username/projects/getrandomdate/node_modules/express/lib/router/index.js:332:14)

unrelated error, but no way to notify author since he's disabled issues. When using moment() objects, the easyXml serializer craps out.

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.