xmlrun

0.0.22 • Public • Published

xmlrun

Convert xml to a tree of objects with a run function to traverse all of them

usage

in node.js

let xmlrun = require('xmlrun');
let runner = xmlrun('xml text');
runner.setRunner('default', function(target) {
    let result = {
        type: xmlrun.utils.getNodeTypeDesc(target.type),
        tagName: target.tag,
        attributes: target.attr,
        value: target.val,
        children: []
    }
    if(!!target.child) {
        result.children = target.child.reduce((acc, cur) => {
            acc.push(cur.run());
            return acc;
        }, []);
    }
    return result;
});
let result = runner.run();
console.log(JSON.stringify(result, null, 2));

description

xmlrun use DOMParser provided by xmldom or browser env to build a node tree with a run method for each node. run the method with proper runner then the method will tranverse all node recursively. currently, it should be done by runner manually.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.22
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.22
    1
  • 0.0.1
    0

Package Sidebar

Install

npm i xmlrun

Weekly Downloads

1

Version

0.0.22

License

MIT

Unpacked Size

6.6 kB

Total Files

3

Last publish

Collaborators

  • fillano