{"id":15069831,"url":"https://github.com/oozcitak/xmlbuilder2","last_synced_at":"2025-05-14T04:05:02.393Z","repository":{"id":36059277,"uuid":"170750231","full_name":"oozcitak/xmlbuilder2","owner":"oozcitak","description":"An XML builder for node.js","archived":false,"fork":false,"pushed_at":"2024-10-29T16:17:42.000Z","size":5748,"stargazers_count":378,"open_issues_count":36,"forks_count":36,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T10:43:51.431Z","etag":null,"topics":["javascript","node-js","xml","xml-builder","xml-parser","xml-serializer","xmlbuilder"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oozcitak.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"open_collective":"oozcitak"}},"created_at":"2019-02-14T20:00:12.000Z","updated_at":"2025-03-04T10:11:38.000Z","dependencies_parsed_at":"2023-01-16T12:34:20.841Z","dependency_job_id":"c939100a-d85e-4770-917a-f942795d7669","html_url":"https://github.com/oozcitak/xmlbuilder2","commit_stats":{"total_commits":884,"total_committers":20,"mean_commits":44.2,"dds":"0.23303167420814475","last_synced_commit":"723a92bb3dea2334a75e7e227c4c9387a8b8bf8c"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oozcitak%2Fxmlbuilder2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oozcitak%2Fxmlbuilder2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oozcitak%2Fxmlbuilder2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oozcitak%2Fxmlbuilder2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oozcitak","download_url":"https://codeload.github.com/oozcitak/xmlbuilder2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312062,"owners_count":20918343,"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","node-js","xml","xml-builder","xml-parser","xml-serializer","xmlbuilder"],"created_at":"2024-09-25T01:45:00.531Z","updated_at":"2025-04-10T19:35:25.207Z","avatar_url":"https://github.com/oozcitak.png","language":"TypeScript","funding_links":["https://opencollective.com/oozcitak","https://opencollective.com/xmlbuilder2"],"categories":[],"sub_categories":[],"readme":"# xmlbuilder2\n\nAn XML builder for [node.js](https://nodejs.org/).\n\n[![License](https://badgen.net/github/license/oozcitak/xmlbuilder2)](http://opensource.org/licenses/MIT)\n[![NPM Version](https://badgen.net/npm/v/xmlbuilder2)](https://www.npmjs.com/package/xmlbuilder2)\n[![NPM Downloads](https://badgen.net/npm/dm/xmlbuilder2)](https://www.npmjs.com/package/xmlbuilder2)\n[![jsDelivr](https://badgen.net/jsdelivr/hits/npm/xmlbuilder2)](https://www.jsdelivr.com/package/npm/xmlbuilder2)\n\n[![Node.js CI](https://github.com/oozcitak/xmlbuilder2/workflows/build/badge.svg)](https://github.com/oozcitak/xmlbuilder2/actions)\n[![Code Coverage](https://codecov.io/gh/oozcitak/xmlbuilder2/branch/master/graph/badge.svg)](https://codecov.io/gh/oozcitak/xmlbuilder2)\n[![Dev Dependency Status](https://badgen.net/david/dep/oozcitak/xmlbuilder2)](https://david-dm.org/oozcitak/xmlbuilder2)\n\n### Installation:\n\n``` sh\nnpm install xmlbuilder2\n```\n\n### Documentation:\n\nSee: https://oozcitak.github.io/xmlbuilder2/\n\n\n### Usage:\n\n`xmlbuilder2` is a wrapper around DOM nodes which adds chainable functions to make it easier to create and work with XML documents. For example the following XML document:\n\n``` xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003croot att=\"val\"\u003e\n  \u003cfoo\u003e\n    \u003cbar\u003efoobar\u003c/bar\u003e\n  \u003c/foo\u003e\n  \u003cbaz/\u003e\n\u003c/root\u003e\n```\n\ncan be created with the following function chain:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst root = create({ version: '1.0' })\n  .ele('root', { att: 'val' })\n    .ele('foo')\n      .ele('bar').txt('foobar').up()\n    .up()\n    .ele('baz').up()\n  .up();\n\n// convert the XML tree to string\nconst xml = root.end({ prettyPrint: true });\nconsole.log(xml);\n```\n\n___\n\nThe same XML document can be created by converting a JS object into XML nodes:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst obj = {\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    },\n    baz: {}\n  }\n};\n\nconst doc = create(obj);\nconst xml = doc.end({ prettyPrint: true });\nconsole.log(xml);\n```\n___\n\n`xmlbuilder2` can also parse and serialize XML documents from different formats:\n```js\nconst { create } = require('xmlbuilder2');\n\nconst xmlStr = '\u003croot att=\"val\"\u003e\u003cfoo\u003e\u003cbar\u003efoobar\u003c/bar\u003e\u003c/foo\u003e\u003c/root\u003e';\nconst doc = create(xmlStr);\n\n// append a 'baz' element to the root node of the document\ndoc.root().ele('baz');\n\nconst xml = doc.end({ prettyPrint: true });\nconsole.log(xml);\n```\nwhich would output the same document string at the top of this page.\n\nOr you could return a JS object by changing the `format` argument to `'object'`:\n```js\nconst obj = doc.end({ format: 'object' });\nconsole.log(obj);\n```\n```js\n{\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    },\n    baz: {}\n  }\n}\n```\n\n___\n\nYou can convert between formats in one go with the `convert` function:\n\n```js\nconst { convert } = require('xmlbuilder2');\n\nconst xmlStr = '\u003croot att=\"val\"\u003e\u003cfoo\u003e\u003cbar\u003efoobar\u003c/bar\u003e\u003c/foo\u003e\u003c/root\u003e';\nconst obj = convert(xmlStr, { format: \"object\" });\n\nconsole.log(obj);\n```\n```js\n{\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    }\n  }\n}\n```\n\n___\n\nIf you need to do some processing:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst root = create().ele('squares');\nroot.com('f(x) = x^2');\nfor(let i = 1; i \u003c= 5; i++)\n{\n  const item = root.ele('data');\n  item.att('x', i);\n  item.att('y', i * i);\n}\n\nconst xml = root.end({ prettyPrint: true });\nconsole.log(xml);\n```\n\nThis will result in:\n\n``` xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003csquares\u003e\n  \u003c!-- f(x) = x^2 --\u003e\n  \u003cdata x=\"1\" y=\"1\"/\u003e\n  \u003cdata x=\"2\" y=\"4\"/\u003e\n  \u003cdata x=\"3\" y=\"9\"/\u003e\n  \u003cdata x=\"4\" y=\"16\"/\u003e\n  \u003cdata x=\"5\" y=\"25\"/\u003e\n\u003c/squares\u003e\n```\n\n### Usage in the browser:\n\nYou can build the minified production bundle (`lib/xmlbuilder2.min.js`) after cloning the repository and issuing `npx webpack` in your terminal. The bundle is also in the npm package, so you can also use a public npm CDN like [jsDelivr](https://www.jsdelivr.com/) or [unpkg](https://unpkg.com/):\n\n```html\n\u003c!-- latest version from jsDelivr --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/xmlbuilder2/lib/xmlbuilder2.min.js\"\u003e\u003c/script\u003e\n\u003c!-- latest version from unpkg --\u003e\n\u003cscript src=\"https://unpkg.com/xmlbuilder2/lib/xmlbuilder2.min.js\"\u003e\u003c/script\u003e\n```\n\n### Donations:\nPlease consider becoming a backer or sponsor to help support development.\n\n[\u003cimg src=\"https://opencollective.com/webpack/donate/button@2x.png?color=blue\" alt=\"Donate Button\" width=\"300\"/\u003e](https://opencollective.com/xmlbuilder2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foozcitak%2Fxmlbuilder2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foozcitak%2Fxmlbuilder2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foozcitak%2Fxmlbuilder2/lists"}