{"id":19166000,"url":"https://github.com/manojc/xtagger","last_synced_at":"2025-07-08T01:36:57.317Z","repository":{"id":57402339,"uuid":"145165041","full_name":"manojc/xtagger","owner":"manojc","description":"A simple node package to get the XML structure of xml file using streams!","archived":false,"fork":false,"pushed_at":"2018-10-05T19:29:01.000Z","size":7034,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T02:13:48.504Z","etag":null,"topics":["sax","sax-parser","stream","xml","xml-node","xml-parser","xml-parsing"],"latest_commit_sha":null,"homepage":"https://runkit.com/manojc/5b8c39bc808c3400127a2868","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manojc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-17T20:44:47.000Z","updated_at":"2018-10-05T19:29:03.000Z","dependencies_parsed_at":"2022-09-26T17:01:04.085Z","dependency_job_id":null,"html_url":"https://github.com/manojc/xtagger","commit_stats":null,"previous_names":["manojc/xtag"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/manojc/xtagger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojc%2Fxtagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojc%2Fxtagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojc%2Fxtagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojc%2Fxtagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manojc","download_url":"https://codeload.github.com/manojc/xtagger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojc%2Fxtagger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259659667,"owners_count":22891672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sax","sax-parser","stream","xml","xml-node","xml-parser","xml-parsing"],"created_at":"2024-11-09T09:30:27.579Z","updated_at":"2025-06-22T00:06:12.212Z","avatar_url":"https://github.com/manojc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/manojc/xtagger.svg?branch=master)](https://travis-ci.com/manojc/xtagger)\n\n# Why [xtagger](https://www.npmjs.com/package/xtagger)?\n\n`xtagger` is a simple node package based on [sax](https://www.npmjs.com/package/sax) to get the XML structure of xml file using streams!\n\nThis package is useful in case you want to read a huge xml file in chunks. There are few npm packages like [xml-flow](https://www.npmjs.com/package/xml-flow) \u0026 [xml-stream](https://www.npmjs.com/package/xml-stream) which accept a repeating node to parse one xml node at a time using streams. The problem here is - **how to find the appropriate repeating xml node?**\n\n`xtagger` helps you to find the appropriate node as it outputs the xml structure using streams.\n\nSimply do **`npm i xtagger --save`** to install the package.\n\n## APIs\n\n`xtagger` exposes 2 properties -\n\n### **getXTagger(options)**\n\nThis property is a `function` that triggers `xtagger.` It returns a `duplex stream` that can be piped with a readbale stream.\n\n`options` manipulates the behavior of xml streamer. Check [sax options](https://www.npmjs.com/package/sax#arguments) for all the details.\n\n### xTaggerEvent: EventEmitter\n\n`xtagger` fires an event after successful data processing. `xTaggerEvent` listens to the fired event \u0026 the event handler function provides the generated xml structure.\n\n## Example\n\n### Typescript\n\n```javascript\nimport { createReadStream } from \"fs\";\nimport { getXTagger, xTaggerEvent } from \"xtagger\";\n\n// options for sax stream API with default values\nconst options: any = {\n    \"strict\": false,\n    \"trim\": false,\n    \"normalize\": false,\n    \"lowercase\": false,\n    \"xmlns\": false,\n    \"noscript\": false,\n    \"position\": false\n};\n\nxTaggerEvent.once(\"xtagger\", (response: any) =\u003e console.log(response));\ncreateReadStream(\"file-path\").pipe(getXTagger(options));\n```\n\n### Javascript\n\n```javascript\nconst fs = require(\"fs\");\nconst xtagger = require(\"xtagger\");\n\n// options for sax stream API with default values\nconst options = {\n    \"strict\": false,\n    \"trim\": false,\n    \"normalize\": false,\n    \"lowercase\": false,\n    \"xmlns\": false,\n    \"noscript\": false,\n    \"position\": false\n};\n\nxtagger.xTaggerEvent.once(\"xtagger\", (response) =\u003e console.log(response));\nfs.createReadStream(\"file-path\").pipe(xtagger.getXTagger(options));\n```\n\n### Sample XML\n\n```xml\n\u003cbreakfast_menu\u003e\n    \u003cfood\u003e\n        \u003cname\u003eBelgian Waffles\u003c/name\u003e\n        \u003cprice\u003e$5.95\u003c/price\u003e\n        \u003cdescription\u003e\n            Two of our famous Belgian Waffles with plenty of real maple syrup\n        \u003c/description\u003e\n        \u003ccalories\u003e650\u003c/calories\u003e\n    \u003c/food\u003e\n    \u003cfood\u003e\n        \u003cname\u003eStrawberry Belgian Waffles\u003c/name\u003e\n        \u003cprice\u003e$7.95\u003c/price\u003e\n        \u003cdescription\u003e\n            Light Belgian waffles covered with strawberries and whipped cream\n        \u003c/description\u003e\n        \u003ccalories\u003e900\u003c/calories\u003e\n    \u003c/food\u003e\n\u003c/breakfast_menu\u003e\n```\n\n### Output\n\nIn case of above `XML`, the output structure would look like -\n\n```javascript\n{\n    \"breakfast_menu\": { \"1\": 1 },\n    \"food\": { \"2\": 2 },\n    \"name\": { \"3\": 2 },\n    \"price\": { \"3\": 2 },\n    \"description\": { \"3\": 2 },\n    \"calories\": { \"3\": 2}\n}\n```\n\nThe 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.\n\nThe generalised structure format looks like this -\n\n```javascript\nstructure: { [name: string]: { [hierarchy: number]: number } };\n```\n\nIn 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 -\n\n```javascript\n{\n    \"breakfast_menu\": { \"1\": 1 },\n    \"food\": { \"2\": 2 },\n    \"name\": { \"3\": 2 },\n    \"price\": { \"3\": 2 },\n    \"description\": { \"3\": 2, \"4\": 2 }, // description tag is present at level 3 \u0026 4\n    \"calories\": { \"3\": 2}\n}\n```\n\n## Demo\n\nCheckout the [repository](https://github.com/manojc/xtagger). Install dependencies with command **`npm i`** \u0026 run **`npm start`** command to start the demo.\n\n## Test\n\nCheckout the [repository](https://github.com/manojc/xtagger). Install dependencies with command **`npm i`** \u0026 run **`npm run test`** command to run the tests.\n\n---\n\n- Author - Manoj Chalode ([manojc](https://github.com/manojc))\n- Copyright - chalodem@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojc%2Fxtagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanojc%2Fxtagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojc%2Fxtagger/lists"}