{"id":19475462,"url":"https://github.com/artdecocode/rexml","last_synced_at":"2026-05-16T02:05:18.639Z","repository":{"id":51988872,"uuid":"141488057","full_name":"artdecocode/rexml","owner":"artdecocode","description":"Simple XML parsing with a regular expression.","archived":false,"fork":false,"pushed_at":"2021-05-08T12:52:54.000Z","size":152,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T08:29:15.637Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/artdecocode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-07-18T20:42:49.000Z","updated_at":"2021-11-14T00:30:22.000Z","dependencies_parsed_at":"2022-08-27T02:29:29.360Z","dependency_job_id":null,"html_url":"https://github.com/artdecocode/rexml","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Frexml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Frexml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Frexml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Frexml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artdecocode","download_url":"https://codeload.github.com/artdecocode/rexml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240699136,"owners_count":19843509,"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":[],"created_at":"2024-11-10T19:32:57.967Z","updated_at":"2026-05-16T02:05:18.613Z","avatar_url":"https://github.com/artdecocode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rexml\n\n[![npm version](https://badge.fury.io/js/rexml.svg)](https://npmjs.org/package/rexml)\n\n`rexml` is a Node.JS package for simple XML parsing with a regular expression. It's been tested to work for simple use cases (does work on nested tags).\n\n```sh\nyarn add rexml\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/0.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n  * [`extractTags(tag, string): Return`](#extracttagstag-stringarraystringstring-string-return)\n    * [`Return`](#type-return)\n    * [Extracting Multiple Tags](#extracting-multiple-tags)\n  * [`extractProps(string: string, parseValue?: boolean): Object\u003cstring,(boolean|string|number)\u003e`](#extractpropsstring-stringparsevalue-boolean-objectstringbooleanstringnumber)\n  * [`extractTagsSpec(tag: string, string: string): {content, props}[]`](#extracttagsspectag-stringstring-string-content-props)\n- [Copyright](#copyright)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its default and named functions:\n\n```js\nimport rexml, { extractProps, extractTagsSpec, extractPropSpec } from 'rexml'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/2.svg?sanitize=true\" width=\"25\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n### \u003ccode\u003e\u003cins\u003eextractTags\u003c/ins\u003e(\u003c/code\u003e\u003csub\u003e\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`tag: string|!Array\u003cstring\u003e,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`string: string,`\u003cbr/\u003e\u003c/sub\u003e\u003ccode\u003e): \u003ci\u003eReturn\u003c/i\u003e\u003c/code\u003e\nExtract member elements from an XML string. Numbers and booleans will be parsed into their JS types.\n\n - \u003ckbd\u003e\u003cstrong\u003etag*\u003c/strong\u003e\u003c/kbd\u003e \u003cem\u003e\u003ccode\u003e(string \\| !Array\u0026lt;string\u0026gt;)\u003c/code\u003e\u003c/em\u003e: Which tag to extract, e.g., `div`. Can also pass an array of tags, in which case the name of the tag will also be returned.\n - \u003ckbd\u003e\u003cstrong\u003estring*\u003c/strong\u003e\u003c/kbd\u003e \u003cem\u003e`string`\u003c/em\u003e: The XML string.\n\nThe tags are returned as an array with objects containing `content` and `props` properties. The content is the inner content of the tag, and `props` is the attributes specified inside the tag.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/index.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport extractTags from 'rexml'\n\nconst xml = `\n\u003chtml\u003e\n  \u003cdiv id=\"d1\"\n    class=\"example\"\n    contenteditable /\u003e\n  \u003cdiv id=\"d2\" class=\"example\"\u003eHello World\u003c/div\u003e\n\u003c/html\u003e\n`\n\nconst res = extractTags('div', xml)\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n[ { content: '',\n    props: \n     { id: 'd1',\n       class: 'example',\n       contenteditable: true },\n    tag: 'div' },\n  { content: 'Hello World',\n    props: { id: 'd2', class: 'example' },\n    tag: 'div' } ]\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n__\u003ca name=\"type-return\"\u003e`Return`\u003c/a\u003e__: The return type.\n\n\n|     Name     |            Type             |                      Description                       |\n| ------------ | --------------------------- | ------------------------------------------------------ |\n| __content*__ | \u003cem\u003estring\u003c/em\u003e             | The content of the tag, including possible whitespace. |\n| __props*__   | \u003cem\u003e!Object\u003cstring, ?\u003e\u003c/em\u003e | The properties of the element.                         |\n| __tag*__     | \u003cem\u003estring\u003c/em\u003e             | The name of the extracted element.                     |\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/3.svg?sanitize=true\" width=\"15\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n#### Extracting Multiple Tags\n\nIt's possible to give an array of tags which should be extracted from the _XML_ string.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/array.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport extractTags from 'rexml'\n\nconst xml = `\u003chtml\u003e\n  \u003cdiv id=\"d1\"/\u003e\n  \u003cdiv id=\"d2\" class=\"example\"\u003eHello World\u003c/div\u003e\n  \u003cfooter\u003eArt Deco, 2019\u003c/footer\u003e\n\u003c/html\u003e\n`\n\nconst res = extractTags(['div', 'footer'], xml)\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n[ { content: '',\n    props: { id: 'd1' },\n    tag: 'div' },\n  { content: 'Hello World',\n    props: { id: 'd2', class: 'example' },\n    tag: 'div' },\n  { content: 'Art Deco, 2019',\n    props: {},\n    tag: 'footer' } ]\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/4.svg?sanitize=true\" width=\"25\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n### \u003ccode\u003e\u003cins\u003eextractProps\u003c/ins\u003e(\u003c/code\u003e\u003csub\u003e\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`string: string,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`parseValue?: boolean,`\u003cbr/\u003e\u003c/sub\u003e\u003ccode\u003e): \u003ci\u003eObject\u003cstring,(boolean|string|number)\u003e\u003c/i\u003e\u003c/code\u003e\n\nExtracts the properties from the attributes part of the tag and returns them as an object. It will parse values if not specified otherwise.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/extract-props.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { extractProps, extractPropsSpec } from 'rexml'\n\nconst s = `id=\"d2\"\nclass=\"example\"\nvalue=\"123\"\nparsable=\"true\"\nignore=\"false\"\n2-non-spec\nrequired`\n\nconst res = extractProps(s)\nconsole.log(JSON.stringify(res, null, 2))\n\n// don't parse booleans and integers\nconst res2 = extractProps(s, false)\nconsole.log(JSON.stringify(res2, null, 2))\n\n// conform to the spec\nconst res3 = extractPropsSpec(s)\nconsole.log(JSON.stringify(res3, null, 2))\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```json\n{\n  \"id\": \"d2\",\n  \"class\": \"example\",\n  \"value\": 123,\n  \"parsable\": true,\n  \"ignore\": false,\n  \"2-non-spec\": true,\n  \"required\": true\n}\n{\n  \"id\": \"d2\",\n  \"class\": \"example\",\n  \"value\": \"123\",\n  \"parsable\": \"true\",\n  \"ignore\": \"false\",\n  \"2-non-spec\": true,\n  \"required\": true\n}\n{\n  \"id\": \"d2\",\n  \"class\": \"example\",\n  \"value\": 123,\n  \"parsable\": true,\n  \"ignore\": false,\n  \"required\": true\n}\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/5.svg?sanitize=true\" width=\"25\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n### \u003ccode\u003e\u003cins\u003eextractTagsSpec\u003c/ins\u003e(\u003c/code\u003e\u003csub\u003e\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`tag: string,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`string: string,`\u003cbr/\u003e\u003c/sub\u003e\u003ccode\u003e): \u003ci\u003e{content, props}[]\u003c/i\u003e\u003c/code\u003e\n\nSame as the default method, but confirms to the XML specification in defining attributes.\n\n```javascript\nimport { extractTagsSpec } from 'rexml'\n\nconst xml = `\n\u003chtml\u003e\n  \u003cdiv id=\"d1\" class=\"example\" contenteditable /\u003e\n  \u003cdiv 5-non-spec\u003eAttributes cannot start with a number.\u003c/div\u003e\n\u003c/html\u003e`\n\nconst res = extractTagsSpec('div', xml)\n\nconsole.log(JSON.stringify(res, null, 2))\n```\n```json\n[\n  {\n    \"props\": {\n      \"id\": \"d1\",\n      \"class\": \"example\",\n      \"contenteditable\": true\n    },\n    \"content\": \"\"\n  }\n]\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/6.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg width=\"100\" src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\"\n          alt=\"Art Deco\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e   2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg width=\"100\" src=\"https://raw.githubusercontent.com/idiocc/cookies/master/wiki/arch4.jpg\"\n          alt=\"Tech Nation Visa\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartdecocode%2Frexml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartdecocode%2Frexml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartdecocode%2Frexml/lists"}