Skip to content

Commit 2bc7dcf

Browse files
committed
Handle xml namespaces by default
1 parent 60c037f commit 2bc7dcf

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

acceptance_tests/inputs-format.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ EOM
5858
assertEquals "$expected" "$X"
5959
}
6060

61+
testInputXmlNamespaces() {
62+
cat >test.yml <<EOL
63+
<?xml version="1.0"?>
64+
<map xmlns="some-namespace" xmlns:xsi="some-instance" xsi:schemaLocation="some-url">
65+
</map>
66+
EOL
67+
68+
read -r -d '' expected << EOM
69+
map:
70+
+xmlns: some-namespace
71+
+xmlns:xsi: some-instance
72+
+xsi:schemaLocation: some-url
73+
EOM
74+
75+
X=$(./yq e -p=xml test.yml)
76+
assertEquals "$expected" "$X"
77+
78+
X=$(./yq ea -p=xml test.yml)
79+
assertEquals "$expected" "$X"
80+
}
81+
6182

6283
testInputXmlStrict() {
6384
cat >test.yml <<EOL

cmd/constant.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var inputFormat = "yaml"
1111
var xmlAttributePrefix = "+"
1212
var xmlContentName = "+content"
1313
var xmlStrictMode = false
14-
var xmlKeepNamespace = false
15-
var xmlUseRawToken = false
14+
var xmlKeepNamespace = true
15+
var xmlUseRawToken = true
1616

1717
var exitStatus = false
1818
var forceColor = false

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ yq -P sample.json
7272
rootCmd.PersistentFlags().StringVar(&xmlAttributePrefix, "xml-attribute-prefix", "+", "prefix for xml attributes")
7373
rootCmd.PersistentFlags().StringVar(&xmlContentName, "xml-content-name", "+content", "name for xml content (if no attribute name is present).")
7474
rootCmd.PersistentFlags().BoolVar(&xmlStrictMode, "xml-strict-mode", false, "enables strict parsing of XML. See https://pkg.go.dev/encoding/xml for more details.")
75-
rootCmd.PersistentFlags().BoolVar(&xmlKeepNamespace, "xml-keep-namespace", false, "enables keeping namespace after parsing attributes")
76-
rootCmd.PersistentFlags().BoolVar(&xmlUseRawToken, "xml-raw-token", false, "enables using RawToken method instead Token. Commonly disables namespace translations. See https://pkg.go.dev/encoding/xml#Decoder.RawToken for details.")
75+
rootCmd.PersistentFlags().BoolVar(&xmlKeepNamespace, "xml-keep-namespace", true, "enables keeping namespace after parsing attributes")
76+
rootCmd.PersistentFlags().BoolVar(&xmlUseRawToken, "xml-raw-token", true, "enables using RawToken method instead Token. Commonly disables namespace translations. See https://pkg.go.dev/encoding/xml#Decoder.RawToken for details.")
7777

7878
rootCmd.PersistentFlags().BoolVarP(&nullInput, "null-input", "n", false, "Don't read input, simply evaluate the expression given. Useful for creating docs from scratch.")
7979
rootCmd.PersistentFlags().BoolVarP(&noDocSeparators, "no-doc", "N", false, "Don't print document separators (---)")

0 commit comments

Comments
 (0)