{"id":19621358,"url":"https://github.com/commenthol/xml-vs-js","last_synced_at":"2026-06-18T14:32:12.656Z","repository":{"id":57401869,"uuid":"132034368","full_name":"commenthol/xml-vs-js","owner":"commenthol","description":"Convert XML/ HTML to Javascript and vice versa","archived":false,"fork":false,"pushed_at":"2022-03-03T20:04:55.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-02T05:54:18.124Z","etag":null,"topics":["converter","html-to-json","javascript","xml-to-html","xml-to-js","xml-to-json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/commenthol.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-05-03T18:25:39.000Z","updated_at":"2024-01-07T11:29:17.000Z","dependencies_parsed_at":"2022-09-15T18:41:31.866Z","dependency_job_id":null,"html_url":"https://github.com/commenthol/xml-vs-js","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/commenthol/xml-vs-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fxml-vs-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fxml-vs-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fxml-vs-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fxml-vs-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commenthol","download_url":"https://codeload.github.com/commenthol/xml-vs-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fxml-vs-js/sbom","scorecard":{"id":300863,"data":{"date":"2025-08-11","repo":{"name":"github.com/commenthol/xml-vs-js","commit":"614dbeaff8ac9682a0407be57b38703e36175349"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":2,"reason":"dependency not pinned by hash detected -- score normalized to 2","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/commenthol/xml-vs-js/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/commenthol/xml-vs-js/ci.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:30","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: The Unlicense: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T20:35:25.199Z","repository_id":57401869,"created_at":"2025-08-17T20:35:25.199Z","updated_at":"2025-08-17T20:35:25.199Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34495377,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["converter","html-to-json","javascript","xml-to-html","xml-to-js","xml-to-json"],"created_at":"2024-11-11T11:22:39.198Z","updated_at":"2026-06-18T14:32:12.633Z","avatar_url":"https://github.com/commenthol.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xml-vs-js\n\n\u003e Convert XML/ HTML to Javascript and vice versa\n\n[![NPM version](https://badge.fury.io/js/xml-vs-js.svg)](https://www.npmjs.com/package/xml-vs-js/)\n[![Build Status](https://github.com/commenthol/xml-vs-js/workflows/CI/badge.svg?branch=master\u0026event=push)](https://github.com/commenthol/xml-vs-js/actions/workflows/ci.yml?query=branch%3Amaster)\n\nFeatures:\n- Uses [htmlparser2][] to convert from xml to js.\n- Processes html as well as xml - default is `xmlMode=true`.\n- Respects order of elements with `_elems` array.\n- Intented for manipulating/ parsing feeds or xml files where a full DOM is not required.\n- Usage of plain JSON object for easy storage.\n- Handles different xml namespaces.\n\nWhy another xml to js converter?\n\n[xml-js][] uses sax for xml conversion which requires valid xml as input.\nFor manipulation of xml files where input and output is xml, the compact format\ndoes not respect the correct order of elements.\nNon-compact mode on the other hand is cumbersome for access of nodes.\nI wanted to have same JSON format for in- and output.\n\nFor syntax of the Js Object please refer to the test fixtures in `./test/fixtures`\n\n## Table of Contents\n\n\u003c!-- !toc (minlevel=2 omit=\"Table of Contents\") --\u003e\n\n* [Conversion from XML to Js](#conversion-from-xml-to-js)\n  * [Example toJs](#example-tojs)\n  * [Promises API](#promises-api)\n* [Conversion from Js to XML](#conversion-from-js-to-xml)\n  * [Example toXml](#example-toxml)\n  * [Promises API](#promises-api-1)\n  * [Example toXml with order of elems](#example-toxml-with-order-of-elems)\n* [Simplify object](#simplify-object)\n* [License](#license)\n* [References](#references)\n\n\u003c!-- toc! --\u003e\n\n## Conversion from XML to Js\n\n```js\ntoJs(xml, opts, (err, obj) =\u003e {})\n```\n\n- see \u003chttps://github.com/fb55/htmlparser2/wiki/Parser-options\u003e\n- `{String} xml`\n- `{Object} [opts]` - htmlparser2 options\n- `{Object} [opts.xmlMode=true]` - xmlMode is set by default; Set to `false` for html\n- `{Object} [opts.decodeEntities=false]` - decode entities\n- `{Object} [opts.recognizeSelfClosing=true]` - recognize self closing tags in html\n- `{Object} [opts.recognizeCDATA=true]` - recognize CDATA tags in html\n- `{Boolean} [opts.elems]` - set to `false` if output shall not contain `_elems` fields; order of xml elements is not guarateed any longer.\n- `{Boolean} [opts.attrs]` - set to `false` if output shall not contain any attributes `_attrs` fields;\n- `{Boolean} [opts.ns]` - set to `false` if output shall not contain any namespace `_ns` fields;\n- `{Function} cb` - `callback(err, obj)`\n\n### Example toJs\n\n```js\nconst {toJs} = require('xml-vs-js')\n\nconst xml = `\n\u003c?xml version=\"1.0\" encoding=utf-8 ?\u003e\n\u003cfeed xmlns=\"http://www.w3.org/2005/Atom\"\u003e\n  \u003ctitle\u003eExample Feed\u003c/title\u003e\n  \u003centry\u003e\n    \u003ctitle\u003eEntry\u003c/title\u003e\n    \u003clink href=\"http://example.org/2003/12/13/atom03\" /\u003e\n    \u003clink rel=\"alternate\" type=\"text/html\" href=\"http://example.org/2003/12/13/atom03.html\"/\u003e\n  \u003c/entry\u003e\n  \u003centry\u003e\n    \u003ctitle\u003eUpdate\u003c/title\u003e\n  \u003c/entry\u003e\n\u003c/feed\u003e\n`\n\ntoJs(xml, (err, obj) =\u003e {\n  console.log(obj)\n  /*\n  {\n    _elems: ['_PROCESSING', 'feed'],\n    _PROCESSING: {\n      _text: '?xml version=\"1.0\" encoding=utf-8 ?'\n    },\n    feed: {\n      _attrs: {\n        xmlns: 'http://www.w3.org/2005/Atom'\n      },\n      _elems: ['title', 'entry', 'entry'],\n      title: {\n        _elems: ['_text'],\n        _text: 'Example Feed'\n      },\n      entry: [{\n        _elems: ['title', 'link', 'link'],\n        title: {\n          _elems: ['_text'],\n          _text: 'Entry'\n        },\n        link: [{\n          _attrs: {\n            href: 'http://example.org/2003/12/13/atom03'\n          }\n        }, {\n          _attrs: {\n            rel: 'alternate',\n            type: 'text/html',\n            href: 'http://example.org/2003/12/13/atom03.html'\n          }\n        }]\n      }, {\n        _elems: ['title'],\n        title: {\n          _elems: ['_text'],\n          _text: 'Update'\n        }\n      }]\n    }\n  }\n*/    \n})\n```\n\n### Promises API\n\n```js\nconst {toJs} = require('xml-vs-js/promises')\n\nconst obj = await toJs(xml, opts)\n```\n\n## Conversion from Js to XML\n\n```js\ntoXml(obj, opts, (err, xml) =\u003e {})\n```\n\n- `{Object} obj` - the object to convert to xml\n- `{Object} [opts]` - options\n- `{Boolean} [opts.xmlMode=true]` - xmlMode is set by default; Set to `false` for html\n- `{Boolean} [opts.encodeEntities=false]` - encode entities\n\n### Example toXml\n\n\u003e **Note:** `_elems` are optional. In case the field is missing the order of elements returned with `Object.keys()` is used.\n\n```js\nconst {toXml} = require('xml-vs-js')\n\nconst obj = {\n  root: {\n    _COMMENT: ' example wo order of elements ',\n    section: {\n      _attrs: { class: 'blue' },\n      span: ['one', 'four'],\n      _text: 'three',\n      strong: 'two'\n    }\n  }\n}\ntoXml(obj, (err, xml) =\u003e {\n  console.log(xml)\n  // \u003croot\u003e\n  //  \u003c!-- example wo order of elements --\u003e\n  //  \u003csection class=\"blue\"\u003e\n  //  \u003cspan\u003eone\u003c/span\u003e\u003cspan\u003efour\u003c/span\u003ethree\u003cstrong\u003etwo\u003c/strong\u003e\n  //  \u003c/section\u003e\n  // \u003c/root\u003e\n})\n```\n\n### Promises API\n\n```js\nconst {toXml} = require('xml-vs-js/promises')\n\nconst xml = await toXml(obj, opts)\n```\n\n### Example toXml with order of elems\n\n```js\nconst {toXml} = require('xml-vs-js')\n\nconst obj = {\n  _PROCESSING: {\n    _text: '?xml version=\"1.0\" encoding=\"utf-8\"?'\n  },\n  root: {\n    section: {\n      _elems: ['span', 'strong', '_text', 'span'],\n      span: ['one', 'four'],\n      _text: 'three',\n      strong: 'two'\n    }\n  }\n}\ntoXml(obj, (err, xml) =\u003e {\n  console.log(xml)\n  // \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n  // \u003croot\u003e\n  //  \u003csection\u003e\n  //  \u003cspan\u003eone\u003c/span\u003e\u003cstrong\u003etwo\u003c/strong\u003ethree\u003cspan\u003efour\u003c/span\u003e\n  //  \u003c/section\u003e\n  // \u003c/root\u003e\n})\n```\n\n## Simplify object\n\n```js\ntoObj(obj, opts)\n```\n\n- `{Object} obj` - the object to simplify\n- `{Object} [opts]` - options\n- `{Boolean} [opts.elems]` - if `false` remove all _elems props\n- `{Boolean} [opts.attrs]` - if `false` remove all _attrs props\n- `{Boolean} [opts.ns]` - if `false` remove all _ns props\n\n\nTo further simplify the object structure from `toJS` use the `toObj` method:\n\n```js\nconst {toJs, toObj} = require('../promises.js')\n\nconst xml = `\n\u003cfeed xmlns=\"http://www.w3.org/2005/Atom\"\u003e\n  \u003ctitle\u003eExample Feed\u003c/title\u003e\n  \u003centry\u003e\n    \u003ctitle\u003eEntry\u003c/title\u003e\n    \u003clink href=\"http://example.org/2003/12/13/atom03\" /\u003e\n    \u003clink rel=\"alternate\" type=\"text/html\" href=\"http://example.org/2003/12/13/atom03.html\"/\u003e\n  \u003c/entry\u003e\n  \u003centry\u003e\n    \u003ctitle\u003eUpdate\u003c/title\u003e\n  \u003c/entry\u003e\n\u003c/feed\u003e\n`\n\nconst obj = await toJs(xml)\nconst simple = toObj(obj, {elems: false, attrs: true})\nconsole.log(simple)\n/*\n{\n  feed: {\n    _attrs: { xmlns: 'http://www.w3.org/2005/Atom' },\n    title: 'Example Feed',\n    entry: [\n      {\n        title: 'Entry',\n        link: [\n          { _attrs: { href: 'http://example.org/2003/12/13/atom03' } },\n          {\n            _attrs: {\n              rel: 'alternate',\n              type: 'text/html',\n              href: 'http://example.org/2003/12/13/atom03.html'\n            }\n          }\n        ]\n      },\n      { title: 'Update' }\n    ]\n  }\n}\n*/\n```\n\n## License\n\nUnlicense \u003chttps://unlicense.org\u003e\n\n## References\n\n- [htmlparser2][]\n- [xml-js][]\n\n[htmlparser2]: https://www.npmjs.com/package/htmlparser2\n[xml-js]: https://www.npmjs.com/package/xml-js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fxml-vs-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommenthol%2Fxml-vs-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fxml-vs-js/lists"}