You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ This library store them in `attributes`, but most importantly, you can change th
44
44
45
45
***Support Upwards Traversal**:
46
46
By setting `{addParent: true}` option, an extra property named `parent` will be generated along each element so that its parent can be referenced.
47
-
Therefore, anywhere during the traversal of an element node, its children **and** its parent can be easily accessed.
47
+
Therefore, anywhere during the traversal of an element, its children **and** its parent can be easily accessed.
48
48
49
49
***Portable Code**:
50
50
Written purely in JavaScript which means it can be used in Node environment and **browser** environment (via bundlers like browserify/JSPM/Webpack).
@@ -67,7 +67,9 @@ which has merged both `<a>` elements into an array! If you try to convert this b
67
67
which has not preserved the order of elements! This is an inherit limitation in the compact representation
68
68
because output like `{a:{_:{x:"1"}}, b:{_:{x:"2"}}, a:{_:{x:"3"}}}` is illegal (same property name `a` should not appear twice in an object).
69
69
70
-
The non-compact output which is supported by this library will produce more information and always gurantees the order of the elements as they appeared in the XML file.
70
+
The non-compact output, which is supported by this library, will produce more information and always gurantees the order of the elements as they appeared in the XML file.
71
+
72
+
Another drawback of compact output is the resultant element can be an object or an array and therefore makes the client code a little awkwards in terms of extra check of object type before processing.
71
73
72
74
NOTE: Although non-compact output is more accurate representation of original XML than compact version, the non-compact version is verbose and consumes more space.
73
75
This library provides both options. Use `{compact: false}` if you are not sure because it preserves everything;
@@ -150,14 +152,15 @@ The below options are applicable for both `js2xml()` and `json2xml()` functions.
150
152
151
153
| Option | Default | Description |
152
154
|:----------------------|:--------|:------------|
153
-
|`spaces`|`0`| Number of spaces to be used for indenting XML output. |
155
+
|`spaces`|`0`| Number of spaces to be used for indenting XML output. Passing characters like `'` `'` or `'\t'` are also accpeted. |
154
156
|`compact`|`false`| Whether the *input* object is in compact form or not. |
155
157
|`fullTagEmptyElement`|`false`| Whether to produce element without sub-elements as full tag pairs `<a></a>` rather than self closing tag `<a/>`. |
158
+
|`indentCdata`|`false`| Whether to write CData in a new line and indent it. Will generate `<a>\n <![CDATA[foo]]></a>` instead of `<a><![CDATA[foo]]></a>`. |
156
159
|`ignoreDeclaration`|`false`| Whether to ignore writing declaration directives of xml. For example, `<?xml?>` will be ignored. |
157
160
|`ignoreAttributes`|`false`| Whether to ignore writing attributes of the elements. For example, `x="1"` in `<a x="1"></a>` will be ignored |
158
161
|`ignoreComment`|`false`| Whether to ignore writing comments of the elements. That is, no `<!-- -->` will be generated. |
159
162
|`ignoreCdata`|`false`| Whether to ignore writing CData of the elements. That is, no `<![CDATA[ ]]>` will be generated. |
160
-
|`ignoreDoctype`|`false`| Whether to ignore writing Doctype of the elements. That is, no `<!DOCTYPE >` will be generated. |
163
+
|`ignoreDoctype`|`false`| Whether to ignore writing Doctype of the elements. That is, no `<!DOCTYPE ]>` will be generated. |
161
164
|`ignoreText`|`false`| Whether to ignore writing texts of the elements. For example, `hi` text in `<a>hi</a>` will be ignored. |
162
165
163
166
## Convert XML → JS object / JSON
@@ -195,7 +198,7 @@ The below option is applicable only for `xml2json()` function.
195
198
196
199
| Option | Default | Description |
197
200
|:--------------------|:--------|:------------|
198
-
|`spaces`|`0`| Number of spaces to be used for indenting JSON output. |
201
+
|`spaces`|`0`| Number of spaces to be used for indenting JSON output. Passing characters like `'` `'` or `'\t'` are also accpeted. |
Copy file name to clipboardExpand all lines: bin/cli.js
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ var optionalArgs = [
23
23
{arg: 'trim',type: 'flag',option:'trim',desc: 'Any whitespaces surrounding texts will be trimmed.'},
24
24
{arg: 'sanitize',type: 'flag',option:'sanitize',desc: 'Special xml characters will be replaced with entity codes.'},
25
25
{arg: 'native-type',type: 'flag',option:'nativeType',desc: 'Numbers and boolean will be converted (coreced) to native type instead of text.'},
26
+
{arg: 'always-array',type: 'flag',option:'alwaysArray',desc: 'Every element will always be an array type (applicable if --compact is set).'},
26
27
{arg: 'always-children',type: 'flag',option:'alwaysChildren',desc: 'Every element will always contain sub-elements (applicable if --compact is not set).'},
27
28
{arg: 'full-tag',type: 'flag',option:'fullTagEmptyElement',desc: 'XML elements will always be in <a></a> form.'},
28
29
{arg: 'no-decl',type: 'flag',option:'ignoreDeclaration',desc: 'Declaration instruction <?xml ..?> will be ignored.'},
0 commit comments