xmlslicer

Advanced XML Splitting and JSON conversion tools

npm install xmlslicer
8 downloads in the last month

xmlslicer

This is utility designed for use with NodeJS scripts to assist with liberating data from XML feeds and files and converting them into useful JSON snippets.

Using libxmljs as the core XML processing tool, xmlslicer is designed to help you extract the pieces of useful data from XML and leaving the rest. It is designed to be used by people with a good handle on XPath as that is the core technique used to extract the useful bits from the XML.

Installing

For the moment, you are probably best cloning this repository into the node_modules directory of a project that you want to use it in. I'll eventually get around to adding it to npm, promise...

Example Use

var xmlslicer = require('xmlslicer'),
    slicer;

slicer = xmlslicer.run({
    type: 'typeName',
    file: 'where/your/xml/lives.xml',
    regex: /\<Item(.|\n|\r)*?\<\/Item\>/i,
    idExpr: '@ItemID',

    template: {
        id: '@ItemID',
        name: 'req://Item/@Name',
        description: '//Item/Description',

        // initialise the position
        pos: {
            lat: 'float://Item/@Latitude',
            lon: 'float://Item/@Longitude'
        }
    }
});

slicer.on('item', function(index, xmlDoc, itemData) {
});

slicer.on('parsed', function(index, xmlDoc, itemData) {
});

slicer.on('parseError', function(message) {
    console.log(message);
});

Custom Expressions and Lookups

To be completed

Custom Extraction Functions

To be completed

npm loves you