mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 06:10:36 +00:00
fix: keep xml namespace prefixes for tags
This commit is contained in:
parent
df92decbe0
commit
f3538850f2
@ -270,10 +270,16 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
|
|||||||
log.Debug("start element %v", se.Name.Local)
|
log.Debug("start element %v", se.Name.Local)
|
||||||
elem.state = "started"
|
elem.state = "started"
|
||||||
// Build new a new current element and link it to its parent
|
// Build new a new current element and link it to its parent
|
||||||
|
var label = se.Name.Local
|
||||||
|
if dec.prefs.KeepNamespace {
|
||||||
|
if se.Name.Space != "" {
|
||||||
|
label = se.Name.Space + ":" + se.Name.Local
|
||||||
|
}
|
||||||
|
}
|
||||||
elem = &element{
|
elem = &element{
|
||||||
parent: elem,
|
parent: elem,
|
||||||
n: &xmlNode{},
|
n: &xmlNode{},
|
||||||
label: se.Name.Local,
|
label: label,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract attributes as children
|
// Extract attributes as children
|
||||||
|
|||||||
@ -343,7 +343,7 @@ instead of
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
||||||
<item foo="bar">baz</item>
|
<item foo="bar">baz</item>
|
||||||
<item>foobar</item>
|
<xsi:item>foobar</xsi:item>
|
||||||
</map>
|
</map>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -366,10 +366,10 @@ yq --xml-raw-token=false '.' sample.xml
|
|||||||
will output
|
will output
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" some-instance:schemaLocation="some-url">
|
<some-namespace:map xmlns="some-namespace" xmlns:xsi="some-instance" some-instance:schemaLocation="some-url">
|
||||||
<item foo="bar">baz</item>
|
<some-namespace:item foo="bar">baz</some-namespace:item>
|
||||||
<item>foobar</item>
|
<some-instance:item>foobar</some-instance:item>
|
||||||
</map>
|
</some-namespace:map>
|
||||||
```
|
```
|
||||||
|
|
||||||
instead of
|
instead of
|
||||||
@ -377,7 +377,7 @@ instead of
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
|
||||||
<item foo="bar">baz</item>
|
<item foo="bar">baz</item>
|
||||||
<item>foobar</item>
|
<xsi:item>foobar</xsi:item>
|
||||||
</map>
|
</map>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -200,9 +200,9 @@ map:
|
|||||||
+@xmlns:xsi: some-instance
|
+@xmlns:xsi: some-instance
|
||||||
+@xsi:schemaLocation: some-url
|
+@xsi:schemaLocation: some-url
|
||||||
item:
|
item:
|
||||||
- +content: baz
|
+content: baz
|
||||||
+@foo: bar
|
+@foo: bar
|
||||||
- foobar
|
xsi:item: foobar
|
||||||
`
|
`
|
||||||
|
|
||||||
const expectedYAMLWithRawNamespacedAttr = `+p_xml: version="1.0"
|
const expectedYAMLWithRawNamespacedAttr = `+p_xml: version="1.0"
|
||||||
@ -211,20 +211,20 @@ map:
|
|||||||
+@xmlns:xsi: some-instance
|
+@xmlns:xsi: some-instance
|
||||||
+@xsi:schemaLocation: some-url
|
+@xsi:schemaLocation: some-url
|
||||||
item:
|
item:
|
||||||
- +content: baz
|
+content: baz
|
||||||
+@foo: bar
|
+@foo: bar
|
||||||
- foobar
|
xsi:item: foobar
|
||||||
`
|
`
|
||||||
|
|
||||||
const expectedYAMLWithoutRawNamespacedAttr = `+p_xml: version="1.0"
|
const expectedYAMLWithoutRawNamespacedAttr = `+p_xml: version="1.0"
|
||||||
map:
|
some-namespace:map:
|
||||||
+@xmlns: some-namespace
|
+@xmlns: some-namespace
|
||||||
+@xmlns:xsi: some-instance
|
+@xmlns:xsi: some-instance
|
||||||
+@some-instance:schemaLocation: some-url
|
+@some-instance:schemaLocation: some-url
|
||||||
item:
|
some-namespace:item:
|
||||||
- +content: baz
|
+content: baz
|
||||||
+@foo: bar
|
+@foo: bar
|
||||||
- foobar
|
some-instance:item: foobar
|
||||||
`
|
`
|
||||||
|
|
||||||
const xmlWithCustomDtd = `
|
const xmlWithCustomDtd = `
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user