{"name":"xmlbuilder2","version":"4.0.2","keywords":["xml","xmlbuilder"],"author":{"name":"Ozgur Ozcitak","email":"oozcitak@gmail.com"},"license":"MIT","_id":"xmlbuilder2@4.0.2","maintainers":[{"name":"oozcitak","email":"oozcitak@gmail.com"},{"name":"universalhandle","email":"frank@pawpawworks.com"}],"contributors":[],"homepage":"https://github.com/oozcitak/xmlbuilder2","bugs":{"url":"https://github.com/oozcitak/xmlbuilder2/issues"},"dist":{"shasum":"9f5ccc1063241f242f8d4539387575f8788d8661","tarball":"http://registry-npm.ywwl.com/xmlbuilder2/download/xmlbuilder2-4.0.2.tgz","fileCount":83,"integrity":"sha512-dwY9ZQHEGYbPX5QFPf8QKENBfeWKV8i7v40Xb0BEDQF7U6Th+0r7yMRpMIMWgI++GxttE8f8bYEMcYaE1u1IUg==","signatures":[{"sig":"MEUCIQCt8yLNmTvuTF6+B+J7BHpgRKP7pbX9G1xY9UeB6ni4VAIgR6sg2VOpsmrtIAd6vtQEETOj8tPbd/sQ2t+dOcXHfZc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":938870,"size":207329,"noattachment":false,"key":"/xmlbuilder2/-/xmlbuilder2-4.0.2.tgz"},"main":"./lib/index","type":"commonjs","types":"./lib/index.d.ts","engines":{"node":">=20.0"},"gitHead":"25829ab688a56488ebb4cc4990ab28717114c527","scripts":{"test":"tsc && npx publint && tsx --test test/**/*test.ts","cover":"tsc && mkdir -p coverage && tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=./coverage/lcov.info test/**/*test.ts","servedocs":"(cd docs && bundle exec jekyll serve)","publish-public":"tsc && npx publint && npx webpack && npm run cover && npm publish --access public"},"_npmUser":{"name":"oozcitak","email":"oozcitak@gmail.com"},"repository":{"url":"git+https://github.com/oozcitak/xmlbuilder2.git","type":"https"},"_npmVersion":"11.6.0","description":"An XML builder for node.js","directories":{},"_nodeVersion":"24.9.0","dependencies":{"js-yaml":"^4.1.1","@oozcitak/dom":"^2.0.2","@oozcitak/util":"^10.0.0","@oozcitak/infra":"^2.0.2"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.6","glob":"^11.0.3","xpath":"^0.0.34","dedent":"^1.7.0","core-js":"^3.45.1","publint":"^0.3.15","ts-node":"^10.9.2","webpack":"^5.102.0","ts-loader":"^9.5.4","typescript":"^5.9.3","xmlbuilder":"^15.1.1","@types/node":"^24.7.0","webpack-cli":"^6.0.1","babel-loader":"^10.0.0","@types/dedent":"^0.7.2","@types/js-yaml":"^4.0.9","harmony-reflect":"^1.6.2","@babel/preset-env":"^7.28.3","es6-proxy-polyfill":"^2.1.1","@babel/runtime-corejs3":"7.10.3","node-polyfill-webpack-plugin":"^4.1.0"},"_npmOperationalInternal":{"tmp":"tmp/xmlbuilder2_4.0.2_1764580317754_0.5842744625220062","host":"s3://npm-registry-packages-npm-production"},"readme":"# xmlbuilder2\n\nAn XML builder for [node.js](https://nodejs.org/).\n\n![GitHub License](https://img.shields.io/github/license/oozcitak/xmlbuilder2)\n![NPM Version](https://img.shields.io/npm/v/xmlbuilder2)\n![NPM Downloads](https://img.shields.io/npm/dm/xmlbuilder2)\n![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/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\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/oozcitak)](https://github.com/sponsors/oozcitak)\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<?xml version=\"1.0\"?>\n<root att=\"val\">\n  <foo>\n    <bar>foobar</bar>\n  </foo>\n  <baz/>\n</root>\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 = '<root att=\"val\"><foo><bar>foobar</bar></foo></root>';\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 = '<root att=\"val\"><foo><bar>foobar</bar></foo></root>';\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 <= 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<?xml version=\"1.0\"?>\n<squares>\n  <!-- f(x) = x^2 -->\n  <data x=\"1\" y=\"1\"/>\n  <data x=\"2\" y=\"4\"/>\n  <data x=\"3\" y=\"9\"/>\n  <data x=\"4\" y=\"16\"/>\n  <data x=\"5\" y=\"25\"/>\n</squares>\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<!-- latest version from jsDelivr -->\n<script src=\"https://cdn.jsdelivr.net/npm/xmlbuilder2/lib/xmlbuilder2.min.js\"></script>\n<!-- latest version from unpkg -->\n<script src=\"https://unpkg.com/xmlbuilder2/lib/xmlbuilder2.min.js\"></script>\n```\n\n### Donations:\nPlease consider becoming a sponsor to help support development.\n\n[:heart: Github Sponsors](https://github.com/sponsors/oozcitak)\n","publish_time":1764580317995,"_cnpm_publish_time":1764580317995,"dist-tags":{"latest":"4.0.3"}}