From 7159002aef84c4fe33e6868d0076d97c44b4d6d5 Mon Sep 17 00:00:00 2001 From: Karol Date: Tue, 3 Oct 2023 13:43:03 +0200 Subject: [PATCH] filter namespaces to only include new namespaces on each node, when generation json --- lib/dachsfisch/xml2_json_converter.rb | 2 +- spec/support/examples.rb | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/dachsfisch/xml2_json_converter.rb b/lib/dachsfisch/xml2_json_converter.rb index d57ebb4..490f2e1 100644 --- a/lib/dachsfisch/xml2_json_converter.rb +++ b/lib/dachsfisch/xml2_json_converter.rb @@ -77,7 +77,7 @@ def handle_attributes(hash, node) end def add_namespaces_to_active_namespaces(node) - node.namespaces.transform_keys {|k| convert_namespace_key(k) } + node.namespaces.reject {|k, v| node.parent.namespaces[k] == v }.transform_keys {|k| convert_namespace_key(k) } end def convert_namespace_key(key) diff --git a/spec/support/examples.rb b/spec/support/examples.rb index 8d14e1a..893389f 100644 --- a/spec/support/examples.rb +++ b/spec/support/examples.rb @@ -160,28 +160,20 @@ def self.xml end end - class Example9 < ExampleBase + class Example9Modified < ExampleBase def self.json <<~JSON { "alice": { - "bob": { - "$1": "david", - "@xmlns": { - "charlie": "http://some-other-namespace", - "$": "http://some-namespace" - } - }, - "charlie:edgar": { - "$1": "frank", - "@xmlns": { - "charlie": "http://some-other-namespace", - "$": "http://some-namespace" - } - }, "@xmlns": { "charlie": "http://some-other-namespace", "$": "http://some-namespace" + }, + "bob": { + "$1": "david" + }, + "charlie:edgar": { + "$1": "frank" } } }