js2xml
Convert arbitary javascript to simple XML. Developed for ApiAxle.
Last updated 9 months ago by philjackson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install js2xml 
SYNC missed versions from official npm registry.

About

A very simple library that converts a simple data structure into XML. Doesn't support namespaces or attributes, just very simple output. This allows you to write JSON and XML from the same structure without a middle-man.

It's written in Coffeescript but the JS is included.

Installing

$ npm install js2xml

Usage

var Js2Xml = require("js2xml").Js2Xml;

var person = {
  name: "Phil Jackson",
  mood: "Bored",
  stuff: [ "love, "puppies", 2, 2.3, { one: { two: "three" } } ],
  morestuff: { milkshake: "banana" }
};

var js2xml = new Js2Xml("person", person);
js2xml.toString();

Gives:

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <name>Phil Jackson</name>
  <mood>Bored</mood>
  <stuff>
    <item>love</item>
    <item>puppies</item>
    <item>2</item>
    <item>2.3</item>
    <item>
      <one>
        <two>three</two>
      </one>
    </item>
  </stuff>
  <morestuff>
    <milkshake>banana</milkshake>
  </morestuff>
</person>

Pluralisation of lists

Here's how you might override the pluralisation function to deal with anonymous list items in Coffeescript:

class AppleXml extends Js2Xml
  @map =
    "apples": "apple"

  pluralisation: ( name ) ->
    return @constructor.map[ name ] or "item"

Current Tags

  • 1.0.9                                ...           latest (9 months ago)

15 Versions

  • 1.0.9                                ...           9 months ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.0                                ...           7 years ago
  • 0.0.7                                ...           7 years ago
  • 0.0.6                                ...           8 years ago
  • 0.0.5                                ...           8 years ago
  • 0.0.4                                ...           8 years ago
  • 0.0.3                                ...           8 years ago
  • 0.0.2                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 5
Dependencies (1)
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |