mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Improving xml docs
This commit is contained in:
parent
1ab535db5e
commit
d289ddc7e3
@ -41,13 +41,13 @@ var xmlScenarios = []xmlScenario{
|
||||
{
|
||||
description: "Parse xml: array",
|
||||
subdescription: "Consecutive nodes with identical xml names are assumed to be arrays.",
|
||||
inputXml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>1</animal><animal>2</animal>",
|
||||
inputXml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>1</animal>\n<animal>2</animal>",
|
||||
expected: "D0, P[], (doc)::animal:\n - \"1\"\n - \"2\"\n",
|
||||
},
|
||||
{
|
||||
description: "Parse xml: attributes",
|
||||
subdescription: "Attributes are converted to fields, with the attribute prefix.",
|
||||
inputXml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cat legs=\"4\"><legs>7</legs></cat>",
|
||||
inputXml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cat legs=\"4\">\n <legs>7</legs>\n</cat>",
|
||||
expected: "D0, P[], (doc)::cat:\n +legs: \"4\"\n legs: \"7\"\n",
|
||||
},
|
||||
{
|
||||
|
@ -4,7 +4,12 @@ At the moment, `yq` only supports decoding `xml` (into one of the other supporte
|
||||
|
||||
As yaml does not have the concept of attributes, these are converted to regular fields with a prefix to prevent clobbering. Consecutive xml nodes with the same name are assumed to be arrays.
|
||||
|
||||
All values in XML are assumed to be strings.
|
||||
All values in XML are assumed to be strings - but you can use `from_yaml` to parse them into their correct types:
|
||||
|
||||
|
||||
```
|
||||
yq e -p=xml '.myNumberField |= from_yaml' my.xml
|
||||
```
|
||||
|
||||
## Parse xml: simple
|
||||
Given a sample.xml file of:
|
||||
@ -27,7 +32,8 @@ Consecutive nodes with identical xml names are assumed to be arrays.
|
||||
Given a sample.xml file of:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<animal>1</animal><animal>2</animal>
|
||||
<animal>1</animal>
|
||||
<animal>2</animal>
|
||||
```
|
||||
then
|
||||
```bash
|
||||
@ -46,7 +52,9 @@ Attributes are converted to fields, with the attribute prefix.
|
||||
Given a sample.xml file of:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cat legs="4"><legs>7</legs></cat>
|
||||
<cat legs="4">
|
||||
<legs>7</legs>
|
||||
</cat>
|
||||
```
|
||||
then
|
||||
```bash
|
||||
|
Loading…
Reference in New Issue
Block a user