basant307/AI_Governance_Project
048
1# fast-xml-builder2Build XML from JSON3 4[](https://npm-compare.com/fast-xml-builder) 5[](https://www.npmjs.com/package/fast-xml-builder)6[](https://github.com/NaturalIntelligence/fast-xml-builder)7 8XML Builder was part of [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) for years. But considering that any bug in the parser may false-alarm users who are only using the builder, we have decided to split it into a separate package.9 10## Installation11 12```bash13npm install fast-xml-builder14```15 16## Usage17 18```javascript19import XMLBuilder from 'fast-xml-builder';20 21const builder = new XMLBuilder();22const xml = builder.build({ name: 'value' });23```24 25fast-xml-builder fully supports the response generated by fast-xml-parser. You can use options like `preserveOrder`, `ignoreAttributes`, `attributeNamePrefix`, `textNodeName`, `cdataPropName`, `commentPropName`, `format`, `indentBy`, `suppressEmptyNode`, `suppressUnpairedNode`, `stopNodes`, `oneListGroup`, `maxNestedTags`, and many more.26 27## Default Options28 29```js30{31 attributeNamePrefix: '@_',32 attributesGroupName: false,33 textNodeName: '#text',34 ignoreAttributes: true,35 cdataPropName: false,36 commentPropName: false,37 format: false,38 indentBy: ' ',39 suppressEmptyNode: false,40 suppressUnpairedNode: true,41 suppressBooleanAttributes: true,42 preserveOrder: false,43 processEntities: true,44 unpairedTags: [],45 stopNodes: [],46 oneListGroup: false,47 maxNestedTags: 100,48 jPath: true,49 tagValueProcessor: (key, val) => val,50 attributeValueProcessor: (attrName, val) => val,51}52```53 54## Options Reference55 56Check [Options reference](docs/Builder_v1.md) for more detail and examples.57 58- **arrayNodeName**: When building XML from an array, set `arrayNodeName` to wrap each element in a tag name.59- **attributeNamePrefix**: Prefix used to identify attribute properties in the JS object. Default: `'@_'`.60- **attributesGroupName**: Group name for attributes in the JS object. When set, all attributes are expected to be nested under this key. Not supported with `preserveOrder: true`.61- **attributeValueProcessor**: Customize how attribute values are serialized. Receives the attribute name and value.62- **cdataPropName**: Property name that identifies CDATA content. Values under this key are wrapped in `<![CDATA[...]]>`.63- **commentPropName**: Property name that identifies comment content. Values under this key are rendered as `<!-- ... -->`.64- **format**: By default, output is a single-line XML string. Set `format: true` for human-readable, indented output.65- **ignoreAttributes**: By default (`true`), attributes are skipped. Set to `false` to include them. Also supports selective ignoring via an array of strings, array of regular expressions, or a callback function.66- **indentBy**: String used for each level of indentation. Default: `' '` (two spaces). Only applies when `format: true`.67- **maxNestedTags**: Limits the maximum depth of nested tags. An error is thrown if this depth is exceeded. Default: `100`.68- **oneListGroup**: Groups all repeated child tags under a single parent tag.69- **preserveOrder**: When a JS object was produced by XMLParser with `preserveOrder: true`, pass the same option to XMLBuilder to reconstruct the original XML correctly.70- **processEntities**: When `true` (default), special characters in text and attribute values are replaced with XML entities (`&`, `<`, etc.). Set to `false` for a performance boost when you know your content has no entities. Note: quotes in attribute values are always escaped regardless of this setting.71- **stopNodes**: Tags listed here are treated as raw content containers — their text content is written as-is without entity encoding. Accepts an array of tag name strings or `Expression` instances from `path-expression-matcher`. The old `*.tagName` wildcard syntax is still accepted and automatically converted to the equivalent `..tagName` deep-wildcard syntax.72- **suppressBooleanAttributes**: When `true` (default), attributes with the value `true` are rendered without the value (e.g. `<tag attr>` instead of `<tag attr="true">`).73- **suppressEmptyNode**: When `true`, tags with no text value are rendered as self-closing (`<tag/>`).74- **suppressUnpairedNode**: When `true` (default), unpaired tags are rendered without a closing slash (`<br>`). When `false`, they are rendered as `<br/>`.75- **tagValueProcessor**: Customize how tag text values are serialized. Receives the tag name and value.76- **textNodeName**: Property name representing the text content of a tag in the JS object. Default: `'#text'`.77- **unpairedTags**: List of tag names that have no matching closing tag (e.g. `<br>` in HTML).78 