npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

xtagger

v0.1.5

Published

A simple node package to get xml strucutre from XML files using streams!

Downloads

11

Readme

xtagger

A simple node package based on sax to get the XML structure of xml file using streams!

Simply do npm i xtagger --save to install the package.

APIs

xtagger exposes 2 properties -

getXTagger(options)

This property is a function that triggers xtagger. It returns a duplex stream that can be piped with a readbale stream.

options manipulates the behavior of xml streamer. Check sax options for all the details.

xTaggerEvent: EventEmitter

xtagger fires an event after successful data processing. xTaggerEvent listens to the fired event & the event handler function provides the generated xml structure.

Example

Typescript

import { createReadStream } from "fs";
import { getXTagger, xTaggerEvent } from "xtagger";

// options for sax stream API with default values
const options: any = {
    "strict": false,
    "trim": false,
    "normalize": false,
    "lowercase": false,
    "xmlns": false,
    "noscript": false,
    "position": false
};

xTaggerEvent.once("xtagger", (response: any) => console.log(response));
createReadStream("file-path").pipe(getXTagger(options));

Javascript

const fs = require("fs");
const xtagger = require("xtagger");

// options for sax stream API with default values
const options = {
    "strict": false,
    "trim": false,
    "normalize": false,
    "lowercase": false,
    "xmlns": false,
    "noscript": false,
    "position": false
};

xtagger.xTaggerEvent.once("xtagger", (response) => console.log(response));
fs.createReadStream("file-path").pipe(xtagger.getXTagger(options));

Sample XML

<breakfast_menu>
    <food>
        <name>Belgian Waffles</name>
        <price>$5.95</price>
        <description>
            Two of our famous Belgian Waffles with plenty of real maple syrup
        </description>
        <calories>650</calories>
    </food>
    <food>
        <name>Strawberry Belgian Waffles</name>
        <price>$7.95</price>
        <description>
            Light Belgian waffles covered with strawberries and whipped cream
        </description>
        <calories>900</calories>
    </food>
</breakfast_menu>

Output

In case of above XML, the output structure would look like -

{
    "breakfast_menu": { "1": 1 },
    "food": { "2": 2 },
    "name": { "3": 2 },
    "price": { "3": 2 },
    "description": { "3": 2 },
    "calories": { "3": 2}
}

The top level keys represent the tag names. Every tage name is an object where key represents the hierarchy of the tag in xml strcture whereas value is the count of the tag name in the XML file.

The generalised structure format looks like this -

structure: { [name: string]: { [hierarchy: number]: number } };

In case of multiple occurance of the same tag name at different hierarchy levels, tag name gets following JSON structure to provide the distribution of the counts at different hierarchy levels -

{
    "breakfast_menu": { "1": 1 },
    "food": { "2": 2 },
    "name": { "3": 2 },
    "price": { "3": 2 },
    "description": { "3": 2, "4": 2 }, // description tag is present at level 3 & 4
    "calories": { "3": 2}
}

Demo

Checkout the repo. Install dependencies with command npm i & run npm start command to start the demo.

Test

Checkout the repo. Install dependencies with command npm i & run npm run test command to run the tests.