@@ -44,6 +44,24 @@ export interface XMLParseOptions {
44
44
* @default false
45
45
*/
46
46
skipValidation ?: boolean ;
47
+ /**
48
+ * Defines the name of the node under which attributes in the JSON output are grouped.
49
+ * The default is `$` for attributes groups.
50
+ *
51
+ * For example `{ attributeNode: '@attributes ' }` with the following XML:
52
+ * ```xml
53
+ * <innerTag attr="value" />
54
+ * ```
55
+ * Will result in the following JSON:
56
+ * ```json
57
+ * "tag": {
58
+ * "@attributes ": {
59
+ * "attr": "value"
60
+ * }
61
+ * }
62
+ * ```
63
+ */
64
+ attributeNode ?: string ;
47
65
}
48
66
49
67
/**
@@ -74,8 +92,21 @@ export interface XMLStringfyOptions {
74
92
*/
75
93
stripEmptyNodes ?: boolean ;
76
94
/**
77
- * Defines the prefix to use for attributes in the XML string.
78
- * The default is `@` for attributes groups.
95
+ * Defines the name of the `node` to use for attributes in the XML string.
96
+ * The default is `$` for attributes groups.
97
+ *
98
+ * For example `{ attributePrefix: '@attributes ' }` with the following JSON:
99
+ * ```json
100
+ * "tag": {
101
+ * "@attributes ": {
102
+ * "attr": "value"
103
+ * }
104
+ * }
105
+ * ```
106
+ * Will result in the following XML:
107
+ * ```xml
108
+ * <innerTag attr="value" />
109
+ * ```
79
110
*/
80
111
attributePrefix ?: string ;
81
112
}
@@ -156,6 +187,7 @@ export namespace XML {
156
187
157
188
const parserOptions : Partial < X2jOptions > = {
158
189
...ParserDefaults ,
190
+ attributesGroupName : options . attributeNode ?? ParserDefaults . attributesGroupName ,
159
191
ignoreAttributes : options . ignoreAttributes ?? ParserDefaults . ignoreAttributes ,
160
192
trimValues : options . trimValues ?? ParserDefaults . trimValues ,
161
193
removeNSPrefix : options . ignoreNamespacePrefix ?? ParserDefaults . removeNSPrefix
@@ -209,7 +241,7 @@ export namespace XML {
209
241
210
242
const builderOptions : Partial < XmlBuilderOptions > = {
211
243
format : ! ! indentBy ,
212
- attributeNamePrefix : options ?. attributePrefix ?? ParserDefaults . attributeNamePrefix ,
244
+ attributeNamePrefix : ParserDefaults . attributeNamePrefix ,
213
245
attributesGroupName : options ?. attributePrefix ?? ParserDefaults . attributesGroupName ,
214
246
suppressEmptyNode : options ?. stripEmptyNodes === true ,
215
247
indentBy
0 commit comments