Fixed update children problem with xml

This commit is contained in:
Mike Farah
2023-10-05 16:29:12 +11:00
parent b2a3cb47a7
commit b0ff65d6b7
5 changed files with 17 additions and 16 deletions
+5 -6
View File
@@ -129,21 +129,20 @@ zoo:
```
## Parse xml: force all as an array
Because of the way yq works, when updating everything you need to update the children before the parents. By default `..` will match parents first, so we reverse that before updating.
Given a sample.xml file of:
```xml
<zoo><thing><frog>boing</frog></thing></zoo>
```
then
```bash
yq -oy '([..] | reverse | .[]) |= [] + .' sample.xml
yq -oy '.. |= [] + .' sample.xml
```
will output
```yaml
zoo:
thing:
frog: boing
- zoo:
- thing:
- frog:
- boing
```
## Parse xml: attributes