Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.5.2] - 2026-01-07

### Fixed

- Preserve @version and @encoding attributes outside the ?xml node

## [0.5.1] - 2024-04-25

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion lib/oxml/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def traverse_hash(hash, builder)
elsif value.is_a?(Array)
traverse_array(key, value, builder)
elsif value.nil?
builder.element(Utils.camelize(key), 'xsi:nil': 'true')
builder.element(Utils.camelize(key))
builder.pop
else
builder.element(Utils.camelize(key))
builder.text(value)
Expand Down
6 changes: 4 additions & 2 deletions lib/oxml/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def attr(name, str)
@last_attr = "#{name}:#{str}"
return if @delete_namespace_attributes

return if name == :version
return if name == :encoding
# @version and @encoding are attributes of the leading ?xml node we ignore. Checking for the
# empty array detects the ?xml origin. Without the check they would become leading nodes
return if name == :version && @arr.empty?
return if name == :encoding && @arr.empty?

start_element("@#{name}")
text(str)
Expand Down
2 changes: 1 addition & 1 deletion lib/oxml/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OXML
VERSION = '0.5.1'
VERSION = '0.5.2'
end