Giter Club home page Giter Club logo

xml-minify's Introduction

xml-minify

License Build Status

A simple tool that reads XML structures from a source file, filters nodes and attributes against a whitelist and writes the hopefully much smaller result into an target file. As it uses read- and write-streams its able to process very large XML files.

Usage

You can either use xml-minify as a node module or as as CLI. Both ways require a config file. You can specify whitelist-entries for every level, node and attribute. Every element that does not match a whitelist entry, will be removed. Duplicate entries for the same level, node and attributes are not allowed. The first element (level 0) defines the stream-chunks. Only the level-0 entry is allowed to have a path as a filterNode.

[{
    level: 0,
    filterNode: 'root products product',
    keepAttributes: ['id']
  },{
    level: 1,
    filterNode: 'variant',
    attributeFilters: [{color: 'blue'}],
    keepAttributes: ['name'],
  },{
    level: 2,
    filterNode: 'price',
    flatten: true
    }]

Aboves config will transform

<root>
    <products>
        <product id="111" category="jackets">
            <variant color="blue" name="Blue Jacket">
                <price>100.00</price>
            </variant>
            <variant color="red" name="Red Jacket">
                <price>150.00</price>
            </variant>
            <brand>Awesome Clothing Company</brand>
            <bullets name="pros">
                <bullet>
                    <text>Nice color</text>
                </bullet>
                <bullet>
                    <text>Even nicer fit</text>
                </bullet>
            </bullets>
        </product>
        <product id="222" category="jeans">
            <variant color="blue" name="Blue Jeans">
                <price>50.00</price>
            </variant>
            <variant color="red" name="Red Jeans">
                <price>75.00</price>
            </variant>
            <brand>Awesome Clothing Company</brand>
        </product>
    </products>
</root>

into this structure:

<products>
    <product id="111">
        <variant name="Blue Jacket">100.00</variant>
        <bullets name="pros">Nice color;Even nicer fit</bullets>
    </product>
    <product id="222">
        <variant name="Blue Jeans">50.00</variant>
    </product>
</products>

Use xml-minify as CLI

$ npm install -g xml-stream
Usage: xml-minify.js -input -config -output

Options:
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]
  -i, --input   Relative path to XML source file             [string] [required]
  -c, --config  Relative path to config.js file  [string] [default: "config.js"]
  -o, --output  Relative path to XML target file   [string] [default: "out.xml"]

Examples:
  xml-minify.js -i input.xml -c config.xml -o output.xml

Use xml-minify as node module

$ npm install xml-stream

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.