{"id":20521969,"url":"https://github.com/imingyu/forgiving-xml-parser","last_synced_at":"2025-04-14T02:53:03.218Z","repository":{"id":57240163,"uuid":"297885620","full_name":"imingyu/forgiving-xml-parser","owner":"imingyu","description":"An XML/HTML parser and serializer for JavaScript.","archived":false,"fork":false,"pushed_at":"2023-09-26T10:22:08.000Z","size":17098,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T16:55:58.047Z","etag":null,"topics":["forgiving-xml-parser","html","html-parser","html-parsing","html2js","html2json","javascript","json","parser","serializer","transformation","typescript","xml","xml-parser","xml-parsing","xml2js","xml2json"],"latest_commit_sha":null,"homepage":"https://imingyu.github.io/forgiving-xml-parser/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imingyu.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-23T07:15:33.000Z","updated_at":"2024-09-26T15:08:53.000Z","dependencies_parsed_at":"2023-09-26T12:24:59.943Z","dependency_job_id":null,"html_url":"https://github.com/imingyu/forgiving-xml-parser","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fforgiving-xml-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fforgiving-xml-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fforgiving-xml-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fforgiving-xml-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imingyu","download_url":"https://codeload.github.com/imingyu/forgiving-xml-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813829,"owners_count":21165631,"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":["forgiving-xml-parser","html","html-parser","html-parsing","html2js","html2json","javascript","json","parser","serializer","transformation","typescript","xml","xml-parser","xml-parsing","xml2js","xml2json"],"created_at":"2024-11-15T22:33:29.407Z","updated_at":"2025-04-14T02:53:03.199Z","avatar_url":"https://github.com/imingyu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# forgiving-xml-parser\n\n[![Build Status](https://travis-ci.org/imingyu/forgiving-xml-parser.svg?branch=master)](https://travis-ci.org/imingyu/forgiving-xml-parser)\n![image](https://img.shields.io/npm/l/forgiving-xml-parser.svg)\n[![image](https://img.shields.io/npm/v/forgiving-xml-parser.svg)](https://www.npmjs.com/package/forgiving-xml-parser)\n[![image](https://img.shields.io/npm/dt/forgiving-xml-parser.svg)](https://www.npmjs.com/package/forgiving-xml-parser)\n\nEnligsh | [简体中文](./README.zh-CN.md)\n\nAn XML/HTML parser and serializer for JavaScript. [Playground](https://imingyu.github.io/forgiving-xml-parser/)\n\n![spec](./docs/img/ad.png)\n\n# Features\n\n-   Transform XML/HTML to JSON(carry code locationInfo or parse steps)\n-   Transform JSON back to XML\n-   Works with node packages, in browser(like browser such as Miniprogram)\n-   Various options are available to customize the transformation\n    -   custom parsing behavior(souch as allow `node-name` is empty)\n    -   supported events\n    -   custom node parser\n\n# Usage\n\n-   1.install\n\n```bash\n# using npm\nnpm i forgiving-xml-parser -S\n# using yarn\nyarn add forgiving-xml-parser\n```\n\n-   2.include\n\n```javascript\n// in node\nconst ForgivingXmlParser = require('forgiving-xml-parser');\nconst json = ForgivingXmlParser.parse('...');\n\n// in webpack\nimport {parse, serialize, ...} from 'forgiving-xml-parser';\nconst json = parse('...');\n```\n\n```html\n\u003c!-- in browser --\u003e\n\u003cscript src=\"xxx/forgiving-xml-parser.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    // global variable\n    const json = ForgivingXmlParser.parse(\"...\");\n\u003c/script\u003e\n```\n\n-   3.use\n\n```javascript\nconst { parse, serialize, parseResultToJSON, FxParser } = require(\"forgiving-xml-parser\");\n\nconst xml = `\u003cp\u003ehi xml\u003c/p\u003e`;\nconst json = parseResultToJSON(parse(xml), {\n    allowAttrContentHasBr: true,\n    allowNodeNameEmpty: true,\n    allowNodeNotClose: true,\n    allowStartTagBoundaryNearSpace: true,\n    allowEndTagBoundaryNearSpace: true,\n    allowTagNameHasSpace: true,\n    allowNearAttrEqualSpace: true,\n    ignoreTagNameCaseEqual: false,\n    onEvent(type, context, data) {},\n}); // { \"nodes\": [{ \"type\": \"element\", \"name\": \"p\", \"children\": [{ \"type\": \"text\", \"content\": \"hi xml\" }] }] }\n\nserialize(json); // \u003cp\u003ehi xml\u003c/p\u003e\n\nconst fxParser = new FxParser();\nconst json2 = parseResultToJSON(fxParser.parse(xml));\nconsole.log(JSON.stringify(json2) === JSON.stringify(json)); // true\nconsole.log(fxParser.serialize(json2) === serialize(json)); // true\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eEvent trigger timing\u003c/summary\u003e\n\n![Legend](./docs/img/legend.png)\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimingyu%2Fforgiving-xml-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimingyu%2Fforgiving-xml-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimingyu%2Fforgiving-xml-parser/lists"}