Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including js2xml-fork with all npm packages installed. Try it out:

var js2xmlFork = require("js2xml-fork")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

js2xml-fork v1.0.8

Convert arbitary javascript to simple XML. Developed for ApiAxle.


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.


$ npm install js2xml


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);


<?xml version="1.0" encoding="UTF-8"?>
  <name>Phil Jackson</name>

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[ name ] or "item"


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free