{"id":23183467,"url":"https://github.com/alexdrel/xmldom-js","last_synced_at":"2025-08-18T15:31:43.475Z","repository":{"id":33165832,"uuid":"153815833","full_name":"alexdrel/xmldom-js","owner":"alexdrel","description":"Lightweight schema-based XML data extraction to plain objects (JSON)","archived":false,"fork":false,"pushed_at":"2023-01-03T15:17:48.000Z","size":506,"stargazers_count":2,"open_issues_count":14,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-28T19:43:11.320Z","etag":null,"topics":["javascript","typescript-library","xml","xml-parser","xml-schema"],"latest_commit_sha":null,"homepage":null,"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/alexdrel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-19T17:03:45.000Z","updated_at":"2019-07-28T08:44:41.000Z","dependencies_parsed_at":"2023-01-14T23:45:16.714Z","dependency_job_id":null,"html_url":"https://github.com/alexdrel/xmldom-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrel%2Fxmldom-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrel%2Fxmldom-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrel%2Fxmldom-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrel%2Fxmldom-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdrel","download_url":"https://codeload.github.com/alexdrel/xmldom-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230245336,"owners_count":18196134,"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":["javascript","typescript-library","xml","xml-parser","xml-schema"],"created_at":"2024-12-18T09:13:07.988Z","updated_at":"2024-12-18T09:13:08.717Z","avatar_url":"https://github.com/alexdrel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/alexdrel/xmldom-js.svg?branch=master)](https://travis-ci.org/alexdrel/xmldom-js)\n\nxmldom-js\n===\nLightweight schema-based XML data extraction to plain objects (JSON)\n\n### Example\n\nTo read the data from the following XML\n\n```xml\n\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n  \u003crss xmlns:media=\"http://search.yahoo.com/mrss/\" version=\"2.0\"\u003e\n    \u003cchannel\u003e\n      \u003ctitle\u003eMRSS Title\u003c/title\u003e\n\n      \u003citem\u003e\n        \u003ctitle\u003eItem 1\u003c/title\u003e\n        \u003cmedia:content url=\"http://example.com/1.mp4\" medium=\"video\"/\u003e\n        \u003cmedia:comment\u003eItem 1 Comment\u003c/media:comment\u003e\n      \u003c/item\u003e\n\n      \u003citem\u003e\n        \u003ctitle\u003eItem 2\u003c/title\u003e\n        \u003cmedia:content url=\"http://example.com/2.mp4\" medium=\"video\"/\u003e\n        \u003cmedia:comment\u003eItem 2 Comment\u003c/media:comment\u003e\n      \u003c/item\u003e\n\n    \u003c/channel\u003e\n  \u003c/rss\u003e\n```\n\nData extraction schema:\n \n ```js \nimport { attribute, content, string, readXML, prefixNamespace } from \"xmldom-js\";\n\nvar rssSchema = {\n  rss: {\n    channel: {\n      title: content(string),\n      item: [{\n        title: content(string),\n        \"media:content\": { url: attribute() },\n        \"media:comment\": content(string)\n      }]\n    }\n  }\n};\n```\n\nFirst xml is parsed using the browser DOMParser and then read into plain JS objects using the schema:\n\n```js\n  var rssXml = new DOMParser().parseFromString(rssString, \"text/xml\");\n\n  var rssJSON = readXML(rssXml, rssSchema, prefixNamespace);\n```\n\nThe resulting JSON:\n\n```json\n{\n  \"rss\": {\n    \"channel\": {\n      \"title\": \"MRSS Title\",\n      \"item\": [\n        {\n          \"title\": \"Item 1\",\n          \"media:content\": {\n            \"url\": \"http://example.com/1.mp4\"\n          },\n          \"media:comment\": \"Item 1 Comment\"\n        },\n        {\n          \"title\": \"Item 2\",\n          \"media:content\": {\n            \"url\": \"http://example.com/2.mp4\"\n          },\n          \"media:comment\": \"Item 2 Comment\"\n        }\n      ]\n    }\n  }\n}\n```\n\n### Namespace handling\nA few modes for handling of the namespace are available:\n* _ignoreNamespace_ - namespace and prefixes are ignored\n* _prefixNamespace_ - use namespace prefixes as is ignoring namespaceURI. Should not be used if XML is provided by third-party as prefixes are not supposed to be stable, but quite safe for in-house XMLs.\n* _namespaces(defaultURI, { prefix: URI })_ - provide map of supported namespace with URIs.\n\n\n\n## Usage\nNpm compatible packager (webpack) is required. CommonJS and ES6 modules are provided, transpiled to es5.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdrel%2Fxmldom-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdrel%2Fxmldom-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdrel%2Fxmldom-js/lists"}