Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

faketoe

hapijs35deprecated2.1.1

This module is no longer maintained.

XML to JSON converter

xml, json, conversion

readme

faketoe Logo

XML to JSON converter

Build Status

Lead Maintainer: Nathan LaFreniere

Description

faketoe is a simple Node transformation stream for used to convert an XML stream to a JSON object. It is a thin wrapper around node-expat and supports the same interface and events as a node-expat object.

Usage

var Fs = require('fs');
var FakeToe = require('./lib');

var parser = FakeToe.createParser(function (error, result) {
    // `result` is:
    // {
    //     item: {
    //             name: '1',
    //         property: 'a',
    //            child: [
    //             [0] {
    //                     name: '2',
    //                 property: 'a',
    //                    child: [
    //                     [0] {
    //                             name: '3',
    //                         property: 'a'
    //                     },
    //                     [1] {
    //                         name: '4'
    //                     }
    //                 ]
    //             },
    //             [1] {
    //                 name: '5'
    //             }
    //         ],
    //          goblins: {
    //             goblin: [
    //                 [0] {
    //                     type: 'ear'
    //                 },
    //                 [1] {
    //                     type: 'nose'
    //                 },
    //                 [2] {
    //                     type: 'throat'
    //                 }
    //             ]
    //         },
    //                x: {
    //               y: [
    //                 [0] 'a',
    //                 [1] 'b',
    //                 [2] 'c'
    //             ]
    //         },
    //            extra: {
    //             extended: 'yes'
    //         },
    //                z: {
    //             verbose: 'no',
    //               $text: 'a'
    //         }
    //     }
    // }

});

parser.on('text', function (text) {

    console.log('text event: ' + text);
});

parser.on('endElement', function (name) {

    console.log('end element event: ' + name);
});

Fs.createReadStream(__dirname + '/test/test1.xml').pipe(parser);

Methods

createParser(callback)

creates an XML to JSON parser (stream). The callback function signature is function (error, result) where

  • error - internal error condition
  • result - the complete JSON object