{"id":20109695,"url":"https://github.com/izatop/xml2o","last_synced_at":"2025-05-06T10:31:36.631Z","repository":{"id":18154881,"uuid":"83575715","full_name":"izatop/xml2o","owner":"izatop","description":"Helps you convert XML into an object for easy reading.","archived":false,"fork":false,"pushed_at":"2024-11-25T18:51:40.000Z","size":44446,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T18:55:09.419Z","etag":null,"topics":["es6","nodejs","sax","sax-parser","simplexml","typescript","xml","xml-parser","xml-to-js"],"latest_commit_sha":null,"homepage":"","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/izatop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-01T16:24:25.000Z","updated_at":"2023-09-23T20:09:19.000Z","dependencies_parsed_at":"2022-07-25T06:32:10.049Z","dependency_job_id":null,"html_url":"https://github.com/izatop/xml2o","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izatop%2Fxml2o","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izatop%2Fxml2o/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izatop%2Fxml2o/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izatop%2Fxml2o/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izatop","download_url":"https://codeload.github.com/izatop/xml2o/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252665987,"owners_count":21785181,"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":["es6","nodejs","sax","sax-parser","simplexml","typescript","xml","xml-parser","xml-to-js"],"created_at":"2024-11-13T18:09:13.306Z","updated_at":"2025-05-06T10:31:31.620Z","avatar_url":"https://github.com/izatop.png","language":"TypeScript","readme":"# xml2o\n\nHelps you convert XML into an object for easy reading.\n\n## Getting Started\n\nInstall the package:\n\n```bash\nnpm i -S xml2o\n```\n\nLet's convert XML from stream:\n\n```typescript\nimport {convertStream} from 'xml2o';\nimport {createReadStream} from 'fs';\n\nconst node = convertStream(createReadStream('/path/to/file.xml'));\n```\n\nWe can doing same with string:\n\n```typescript\nimport {convertString} from 'xml2o';\n\nconst node = convertString('\u003cnode\u003e\u003cfoo bar=\"bar\"\u003efoo\u003c/foo\u003e\u003c/node\u003e');\n```\n\n## Examples\n\nA SimpleXML-like Node object made to help you read XML structures in JS without DOM.\n\n**Check a node**\n\n```typescript\nimport {convertString} from 'xml2o';\n\nconst xml = `\u003cnode\u003e\n    \u003cfoo bar=\"bar\"\u003efoo\u003c/foo\u003e\n    \u003clist\u003e\n        \u003cbaz id=\"1\" name=\"baz 1\" /\u003e\n        \u003cbaz id=\"2\" name=\"baz 2\" /\u003e\n        \u003cbaz id=\"3\" name=\"baz 3\" /\u003e\n    \u003c/list\u003e\n\u003c/node\u003e`;\n\nconst node = convertString(xml);\nconsole.log(node);\n```\n\n**Root of a node, name and inner text**\n\n```typescript\nconsole.log(\n    node.name,\n    node.text\n);\n```\n\n**Child node name, text and attributes**\n\n```typescript\nconsole.log(\n    node[0].name,\n    node[0].text,\n    node[0].getAttribute('bar'),\n    node[0].getAttributeNode('bar'),\n    node[0].getAttributes()\n)\n```\n\n**Node children**\n```typescript\nconsole.log(...node.map(child =\u003e child.name));\n```\n\n**Node query**\n```typescript\nimport {convertString} from 'xml2o';\n\nconst xml = `\u003cnode\u003e\n    \u003ca/\u003e\n    \u003cb\u003e\n        \u003ca/\u003e\n        \u003ca/\u003e\n        \u003cc\u003e\u003ca/\u003e\u003c/c\u003e\n    \u003c/b\u003e\n    \u003cd\u003e\n        \u003cc\u003e\u003ca/\u003e\u003c/c\u003e\n    \u003c/d\u003e\n\u003c/node\u003e`;\n\nconst node = convertString(xml);\nconsole.log(node.query('/a')); // found /node/a\nconsole.log(node.query('a')); // found /node/a, /node/b/a, /node/b/c/a, /node/d/c/a\nconsole.log(node.query('c/a')); // found /node/b/c/a, /node/d/c/a\nconsole.log(node.query('/d/c')); // found /node/d/c\nconsole.log(node.query('b/a')); // found /node/b/a\n```\n\n## Documentation\n\n| Method | Arguments | Return | Description |\n|---|---|---|---|\n| convertString | `XMLString` | `Node` | XML string\n| convertStream | `stream`    | `Node` | Readable stream\n\n### Node\n\nNode class used to present XML nodes as objects. Every Node object has following properties and methods:\n\n**Properties**\n\n| Property | Description |\n|---|---|\n| `name`         | Tag name\n| `local`        | Tag local name\n| `prefix`       | Tag prefix\n| `parent`       | Parent Node\n| `root`         | Root Node\n\n**Methods**\n\n| Method | Arguments | Return | Description |\n|---|---|---|---|\n| `getAttribute`    | `name, uri?` | `string`           | Returns an attribute value\n| `getAttributeNode`| `name, uri?` | `Attribute`        | Returns an attribute\n| `getAttributes`   |              | `Array\u003cstring\u003e`    | Returns an array of attributes values\n| `hasAttribute`    | `name, uri?` | `boolean`          | Returns true if an attribute is exists \n| `query`           | `name, uri?` | `Array\u003cNode\u003e`      | Returns matched nodes in any level\n\n# Note\nCode examples written with modules so you may need babel, typescript or other to run its or rewrite ES6 imports to: \n\n```js\nconst createString = require('xml2o').createString;\n```\n\nThis library written in ES6 and if you need ES3 build you can tell me i'll make support for older JS versions. \n\n# License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizatop%2Fxml2o","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizatop%2Fxml2o","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizatop%2Fxml2o/lists"}