Skip to content

Commit

Permalink
add example with empty node and attribute, fix overwriting of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Jul 17, 2023
1 parent e63f9a1 commit f986c7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dachsfisch/xml2_json_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def extract_node(node)
hash = {}
active_namespaces = add_namespaces_to_active_namespaces(node)
hash['@xmlns'] = active_namespaces unless active_namespaces.empty?

handle_attributes(hash, node)
node.children.each do |child|
handle_content(hash, child)
handle_attributes(hash, node)
end
hash
end
Expand Down
22 changes: 22 additions & 0 deletions spec/support/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ def self.xml
end
end

class CustomExampleEmptyNodeWithAttribute < ExampleBase
def self.json
<<~JSON
{
"alice": {
"bob": {
"@foo": "bar"
}
}
}
JSON
end

def self.xml
<<-XML
<alice>
<bob foo="bar"/>
</alice>
XML
end
end

class CustomExampleCdata < ExampleBase
def self.json
<<~JSON
Expand Down

0 comments on commit f986c7e

Please sign in to comment.