This commit is contained in:
Mike Farah
2023-09-26 14:50:18 +10:00
parent 4a36926788
commit b06ab987b1
6 changed files with 26 additions and 7 deletions
+19
View File
@@ -128,6 +128,25 @@ zoo:
- cat
```
## 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
```
will output
```yaml
- zoo:
- thing:
- frog:
- boing
```
## Parse xml: attributes
Attributes are converted to fields, with the default attribute prefix '+'. Use '--xml-attribute-prefix` to set your own.