From 6afa3a29d733b9d38875212ffaad37bd07b2b861 Mon Sep 17 00:00:00 2001 From: rndmit Date: Tue, 14 Jun 2022 19:10:40 +0300 Subject: [PATCH] Add tests --- pkg/yqlib/doc/usage/xml.md | 36 +++++++++++++++ pkg/yqlib/xml_test.go | 90 +++++++++++++++++++++++++++++++++++--- 2 files changed, 120 insertions(+), 6 deletions(-) diff --git a/pkg/yqlib/doc/usage/xml.md b/pkg/yqlib/doc/usage/xml.md index fb200381..64a22248 100644 --- a/pkg/yqlib/doc/usage/xml.md +++ b/pkg/yqlib/doc/usage/xml.md @@ -192,6 +192,42 @@ cat: # after cat ``` +## Parse xml: keep attribute namespace +Given a sample.xml file of: +```xml + + + + + +``` +then +```bash +yq -p=xml -o=xml --xml-keep-namespace '.' sample.xml +``` +will output +```xml + +``` + +## Parse xml: keep raw attribute namespace +Given a sample.xml file of: +```xml + + + + + +``` +then +```bash +yq -p=xml -o=xml --xml-keep-namespace --xml-raw-token '.' sample.xml +``` +will output +```xml + +``` + ## Encode xml: simple Given a sample.yml file of: ```yaml diff --git a/pkg/yqlib/xml_test.go b/pkg/yqlib/xml_test.go index a7967e35..cf7fea5f 100644 --- a/pkg/yqlib/xml_test.go +++ b/pkg/yqlib/xml_test.go @@ -153,6 +153,24 @@ var expectedXMLWithComments = ` ` +var inputXMLWithNamespacedAttr = ` + + + +` + +var expectedYAMLWithNamespacedAttr = `map: + +xmlns: some-namespace + +xmlns:xsi: some-instance + +some-instance:schemaLocation: some-url +` + +var expectedYAMLWithRawNamespacedAttr = `map: + +xmlns: some-namespace + +xmlns:xsi: some-instance + +xsi:schemaLocation: some-url +` + var xmlWithCustomDtd = `