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: content/en/docs/Reference/Blocks/xml/convert-xml/convert-structure-to-xml-block.md
+236-70
Original file line number
Diff line number
Diff line change
@@ -12,50 +12,136 @@ description: "Converts a Structure To Xml."
12
12
13
13
## Description
14
14
15
-
Converts a [Structure][Structure Property] to [Xml][Json Property].
15
+
Converts a [Structure][Structure Property] to [Xml][Xml Property].
16
+
17
+
This block will convert a [Structure][Structure Property] into [Xml][Xml Property], with each Key Value Pair being converted into a node with the node name being the Key and the data within the node being the Value.
18
+
19
+
If a Key Value Pair contains a Structure as its value, a node will be added to the value for each Key Value Pair with the inner node name being the Key and the data within the inner node being the Value.
16
20
17
21
## Examples
18
22
19
23
### Convert a Structure to Xml
20
24
21
-
This example will convert `TODO` to its Xml representation.
25
+
This example will convert the [Structure][Structure Property] below to its [Xml][Xml Property] representation.
|[Structure][Structure Property]|`($)Structure`, with value `{TODO}`|`($)Structure` is a variable of type [Structure][]|
46
+
|[Structure][Structure Property]|`($)Structure`, with value `{"topLevelNode": {"@attr" : "exampleAttribute", "id" : ["1","2","3"], "action" : "exampleAction", "#text" : "text without a node"}}`|`($)Structure` is a variable of type [Structure][]|
28
47
|[Xml][Xml Property]|`($)Xml`, with no value |`($)Xml` is a variable that will be set to a [String][] value. |
29
48
30
49
#### Result
31
50
32
-
Converting `{TODO}` to Xml results in the variable `($)Xml` being updated to the following:
51
+
Converting `{"topLevelNode": {"@attr" : "exampleAttribute", "id" : ["1","2","3"], "action" : "exampleAction", "#text" : "text without a node"}}` to Xml results in the variable `($)Xml` being updated to the following:
33
52
34
-
```json
35
-
"TODO"
53
+
```xml
54
+
@"<topLevelNodeattr="exampleAttribute">
55
+
<id>1</id>
56
+
<id>2</id>
57
+
<id>3</id>
58
+
<action>exampleAction</action
59
+
>text without a node
60
+
</topLevelNode>"
36
61
```
37
62
38
-
Explain how conversion works?
39
-
40
63
***
41
64
42
-
### TODO Different examples
65
+
### Convert Nested Structure to Xml
66
+
67
+
This example will convert the [Structure][Structure Property] below to its [Xml][Xml Property] representation.
|[Structure][Structure Property]|`($)Structure`, with value `{ "topLevelNode": {"@attr" : "exampleAttribute", "id" : ["1", "2", "3"], "action" : "exampleAction", "#text" : "text without a node"}}`|`($)Structure` is a variable of type [Structure][]|
89
+
|[Xml][Xml Property]|`($)Xml`, with no value |`($)Xml` is a variable that will be set to a [String][] value. |
90
+
91
+
#### Result
92
+
93
+
```xml
94
+
@"<topLevelNodeattr="exampleAttribute">
95
+
<id>1</id>
96
+
<id>2</id>
97
+
<id>3</id>
98
+
<action>exampleAction</action>
99
+
<innerNode>
100
+
<nestedNode>nested node text</nestedNode>
101
+
inner node text
102
+
</innerNode>
103
+
text without a node
104
+
</topLevelNode>"
105
+
```
106
+
107
+
***
43
108
44
-
TODO
109
+
### Structure Node Example
110
+
111
+
This example will convert the [Structure][Structure Property] below to its [Xml][Xml Property] representation.
|[Structure][Structure Property]|`($)Structure`, with value `{TODO}`|`($)Structure` is a variable of type [Structure][]|
131
+
| [Structure][Structure Property] | `($)Structure`, with value
132
+
`{{ "node1" : "1"}, {"node2" : "2"}, {"node3" : "3"}}` | `($)Structure` is a variable of type [Structure][] |
51
133
|[Xml][Xml Property]|`($)Xml`, with no value |`($)Xml` is a variable that will be set to a [String][] value. |
52
134
53
135
#### Result
54
136
55
-
TODO
137
+
Converting `{{ "node1" : "1"}, {"node2" : "2"}, {"node3" : "3"}}` to [Xml][Xml Property] results in the variable `($)Xml` being updated to the following:
56
138
57
-
```json
58
-
TODO
139
+
```xml
140
+
@"<Cortex_DataTypes_Dictionaries_Structure>
141
+
<node1>1</node1>
142
+
<node2>2</node2>
143
+
<node3>3</node3>
144
+
</Cortex_DataTypes_Dictionaries_Structure>"
59
145
```
60
146
61
147
***
@@ -66,8 +152,6 @@ TODO
66
152
67
153
The [Structure][Structure Property] to convert to [Xml][Xml Property].
@@ -92,16 +174,147 @@ The exceptions thrown by the block can be found below:
92
174
93
175
| Name | Description |
94
176
|----------|----------|
95
-
|[PropertyEmptyException][]| Thrown when [Structure][Structure Property] does not contain any items. |
96
177
|[PropertyNullException][]| Thrown when [Structure][Structure Property] is `null`. |
178
+
|[PropertyEmptyException][]| Thrown when [Structure][Structure Property] does not contain any items. |
97
179
|[XmlSerializationException][]| Thrown when [Structure][Structure Property] has a key that is an empty string. |
180
+
|| Thrown when the [Structure][Structure Property] includes an xml declaration key (e.g. ?xml) or a document type definition key (e.g. !DOCTYPE) that has an invalid attribute key. (e.g. Key: "@test", Value: "testValue"). |
181
+
|| Thrown when the [Structure][Structure Property] includes an attribute key with a [Complex Type][] as a value. (e.g. Key: "@name", Value: new UserCredentials{...}). |
182
+
|| Thrown when the [Structure][Structure Property] includes an xml declaration key (e.g. ?xml) with an attribute that has an invalid primitive value. (e.g. Key: "@version", Value: false). |
183
+
|| Thrown when the [Structure][Structure Property] includes a document type definition key (e.g. !DOCTYPE) that has an attribute with an invalid primitive value. (e.g. Key: "@name", Value: 22). |
98
184
99
185
## Remarks
100
186
101
187
### Round-tripping
102
188
103
189
It should be possible to pass the Xml created by this block to the [Convert Xml To Structure][] block, and then pass the [Structure][Structure Property] created by the [Convert Xml To Structure][] block back to this block; this is called round-tripping.
104
190
191
+
### Attributes
192
+
193
+
If a node requires an attribute, the attribute is defined to a [Key Value Pair][] where the key is the attribute name with an `"@"` before it and the value is the attribute data, for example:
194
+
195
+
```json
196
+
{
197
+
"node": {
198
+
"@attribute": "Attribute Value",
199
+
"innernode": "Inner Node Value"
200
+
}
201
+
}
202
+
```
203
+
204
+
The [Xml][Xml Property] example above would be converted to the following [Structure][Structure Property] be converted to
205
+
206
+
```xml
207
+
@"<nodeattribute="Attribute Value">
208
+
<innerNode>Inner Node Value</innerNode>
209
+
</node>"
210
+
```
211
+
212
+
### Primitive Values Within Attribute Keys
213
+
214
+
Attribute keys may only have [Primitive Values][], an [XmlSerializationException][] will be thrown if a [Complex Value][] is used as an attribute key.
215
+
216
+
### Key Restrictions
217
+
218
+
If provided, the xml declaration key (e.g. ?xml) can only accept following attributes: @version, @encoding and @standalone.
219
+
220
+
If provided, the document type definition key (e.g. !DOCTYPE) can only accept following attributes: @name, @public, @system and @internalSubset.
221
+
222
+
The keys `"$id"`, `"$ref"`, `"$type"` and `"$value"` are reserved words within the XMLConverter. Using them can cause odd behaviour as they are treated like attributes within the conversion.
223
+
224
+
The key `"values"` is also reserved, however it is treated as its own node within the conversion.
225
+
226
+
### Data Not Within a Node
227
+
228
+
If any data does not have any nodes and is within the same element as other data with nodes, the data is converted to a [Key Value Pair][] where the key is "#text" and the value is the node-less data.
229
+
230
+
If data does not require a node and is withiin the same element as other data with nodes, the nodeless data requires a [Key Value Pair][] where the
231
+
232
+
```json
233
+
{
234
+
"node": {
235
+
"innerNode": "Inner Node Value",
236
+
"#text": "Node Value"
237
+
}
238
+
}
239
+
```
240
+
241
+
The [Structure][Structure Property] example above would be converted to the following [Xml][Xml Property].
242
+
243
+
```xml
244
+
@"<node>
245
+
<innerNode>
246
+
Inner Node Value
247
+
</innerNode>
248
+
Node Value
249
+
</node>"
250
+
```
251
+
252
+
### Duplicate Nodes At The Same Level
253
+
254
+
If an multiple duplicate nodes are required at the same level, they are defined using a [Key Value Pair][] where the key is the duplicated node and the value is a list of each duplicate nodes data in order, for example:
The [Structure][Structure Property] example above would be converted to the following [Xml][Xml Property].
266
+
267
+
```xml
268
+
@"<node>
269
+
<duplicateNode>
270
+
First Duplicate Node
271
+
</duplicateNode>
272
+
273
+
<duplicateNode>
274
+
Second Duplicate Node
275
+
</duplicateNode>
276
+
277
+
<distinctNode>
278
+
Distinct Node
279
+
</distinctNode>
280
+
</node>"
281
+
```
282
+
283
+
### Using Non-Alphanumeric Symbols Within Node Names
284
+
285
+
Any non-alphanumeric symbol (i.e. symbols that are not 0 to 9 or a to Z) will be converted to their respective Unicode values when used within a node name. For example, `"!"` and `"&"` are both non-alphanumeric symbols and would be converted to `"x0021"` and `"x0026"` respectively.
286
+
287
+
For more information on characters and their Unicode values please see [Character Sets][]
288
+
289
+
### Structure Node
290
+
291
+
If a root node is not defined, then the root node `""Cortex_DataTypes_Dictionaries_Structure""` will be added during the conversion to ensure that the resulting [Xml][Xml Property] is valid.
292
+
293
+
```json
294
+
{
295
+
{
296
+
"node1" : "1"
297
+
},
298
+
{
299
+
"node2" : "2"
300
+
},
301
+
{
302
+
"node3" : "3"
303
+
}
304
+
}
305
+
```
306
+
307
+
The [Structure][Structure Property] example above would be converted to the following [Xml][Xml Property].
308
+
309
+
```xml
310
+
@"<Cortex_DataTypes_Dictionaries_Structure>
311
+
<node1>1</node1>
312
+
<node2>2</node2>
313
+
<node3>3</node3>
314
+
</Cortex_DataTypes_Dictionaries_Structure>"
315
+
```
316
+
317
+
105
318
[Structure Property]: {{< ref "#structure" >}}
106
319
[Xml Property]: {{< ref "#xml" >}}
107
320
@@ -112,57 +325,10 @@ It should be possible to pass the Xml created by this block to the [Convert Xml
/// If there are multiple items in the specified structure, a root node is automatically added to make it valid xml (added root node: "Cortex_FlowEngine_Core_Types_Structure")
122
-
123
-
/// If a node requires an attribute, use a key value pair where the key is the attribute name with an "@" before it and the value is the attribute data.
124
-
125
-
/// If data does not require nodes and is within the same element as data that does require nodes, use a key value pair where the key is "#text" and the value is the node-less data.
126
-
127
-
/// If multiple of the same nodes are required are within the same element, use a key value pair where the key is the node and the value is a list with the nodes data.
128
-
129
-
/// If the specified structure includes an ampersand symbol in a node's name, the xml will return with "_x0026_" in place of the ampersand symbol.
130
-
131
-
/// If the specified structure includes an ampersand symbol in a node's data, the xml will return with "&" in place of the ampersand symbol.
0 commit comments