Skip to content

Commit

Permalink
filter namespaces to only include new namespaces on each node, when g…
Browse files Browse the repository at this point in the history
…eneration json
  • Loading branch information
kkoehn authored and MrSerth committed Oct 3, 2023
1 parent a8a44a0 commit 96671d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/dachsfisch/xml2_json_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 7 additions & 15 deletions spec/support/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down

0 comments on commit 96671d5

Please sign in to comment.