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
@@ -3198,7 +3198,7 @@ When using a Schema Object with XML, if no XML Object is present, the behavior i
3198
3198
| <a name="xml-wrapped"></a>wrapped | `boolean` | MAY be used only for an array definition. Signifies whether the array is wrapped (for example, `<books><book/><book/></books>`) or unwrapped (`<book/><book/>`). Default value is `false`. The definition takes effect only when defined alongside `type` being `"array"` (outside the `items`). If `nodeType` is present, this field MUST NOT be present.<br /><br />**Deprecated:** Set `nodeType: "element"` explicitly in place of `wrapped: true` |
3199
3199
3200
3200
Note that when generating an XML document from object data, the order of the nodes is undefined.
3201
-
Use `prefixItems` to control node ordering.
3201
+
Use `prefixItems` to control node ordering as shown under [Ordered Elements and Text](#ordered-elements-and-text).
3202
3202
3203
3203
See [Appendix B](#appendix-b-data-type-conversion) for a discussion of converting values of various types to string representations.
3204
3204
@@ -3509,35 +3509,168 @@ components:
3509
3509
</Documentation>
3510
3510
```
3511
3511
3512
-
###### Element With Text Before and After a Child Element
3512
+
Alternatively, the named root element could be set at the point of use and the root element disabled on the component:
3513
3513
3514
-
In this example, `prefixItems` is used to control the ordering.
3515
-
Since `prefixItems` works with arrays, we need to explicitly set the `nodeType` to `element`.
3516
-
Within `prefixItems`, we need to explicitly set the `nodeType` of the `text` nodes, but do not need a name, while the data node's default `nodeType` of `element` is correct, but it needs an explicit `name`:
To control the exact order of elements, use the `prefixItems` keyword.
3578
+
With this approach, it is necessary to set the element names using the XML Object as they would otherwise all inherit the parent's name despite being different elements in a specific order.
3579
+
It is also necessary to set `nodeType: "element"` explicitly on the array in order to get an element containing the sequence.
3580
+
3581
+
This first ordered example shows a sequence of elements, as well as the recommended serialization of `null` for elements:
3517
3582
3518
3583
```yaml
3519
3584
components:
3520
3585
schemas:
3521
-
Report:
3586
+
OneTwoThree:
3587
+
xml:
3588
+
nodeType: element
3522
3589
type: array
3590
+
minLength: 3
3591
+
maxLength: 3
3592
+
prefixItems:
3593
+
- xml:
3594
+
name: One
3595
+
type: string
3596
+
- xml:
3597
+
name: Two
3598
+
type: object
3599
+
required:
3600
+
- unit
3601
+
- value
3602
+
properties:
3603
+
unit:
3604
+
type: string
3605
+
xml:
3606
+
nodeType: attribute
3607
+
value:
3608
+
type: number
3609
+
xml:
3610
+
nodeType: text
3611
+
- xml:
3612
+
name: Three
3613
+
type:
3614
+
- boolean
3615
+
- "null"
3616
+
```
3617
+
3618
+
```xml
3619
+
<OneTwoThree>
3620
+
<One>Some text</One>
3621
+
<Two unit="cubits">42</Two>
3622
+
<Three xsi:nil="true" />
3623
+
</OneTwoThree>
3624
+
```
3625
+
3626
+
The in-memory instance data that would produce the above XML snippet with the preceding schema would be:
3627
+
3628
+
```json
3629
+
[
3630
+
"Some Text",
3631
+
{
3632
+
"unit": "cubits",
3633
+
"value": 42
3634
+
},
3635
+
null
3636
+
]
3637
+
```
3638
+
3639
+
In this next example, the `name` needs to be set for the element, while the `nodeType` needs to be set for the text nodes.
0 commit comments