Skip to content

Commit 0045494

Browse files
committed
chore(docs): XMLBuilder initialIndentationLevel example
1 parent 8fca642 commit 0045494

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/v4/3.XMLBuilder.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,43 @@ Don't consider attributes while building XML. Other attributes related propertie
175175
## indentBy
176176
Applicable only if `format:true` is set.
177177

178+
## initialIndentationLevel
179+
Applicable only if `format:true` is set.
180+
181+
Allows you to specify initial indentation level for the builder, with default value being `0`.
182+
183+
Example of setting `initialIndentationLevel` option to custom value and building XML:
184+
185+
```
186+
const data = {
187+
['trans-unit']: {
188+
source: 'source string',
189+
target: 'target string',
190+
},
191+
};
192+
193+
const options = {
194+
format: true,
195+
initialIndentationLevel: 1,
196+
};
197+
198+
const builder = new XMLBuilder(options);
199+
const result = builder.build(data);
200+
201+
console.log(result);
202+
```
203+
204+
Output:
205+
206+
```
207+
<trans-unit>
208+
<source>source string</source>
209+
<target>target string</target>
210+
</trans-unit>
211+
```
212+
213+
Giving us prefixed xml document by one indentation level.
214+
178215
## preserveOrder
179216
When you parse a XML using XMLParser with `preserveOrder: true`, the result JS object has different structure. So parse that structure in original XML, you should set the same option while building the XML from that js object.
180217

0 commit comments

Comments
 (0)