From 43cfd7389ed48d1ba8992eeb09d70097a93c4d5c Mon Sep 17 00:00:00 2001 From: onli Date: Wed, 7 Jan 2026 10:33:00 +0100 Subject: [PATCH 1/3] Fix: Don't remove version and encoding attributes of all elements --- lib/oxml/parser.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/oxml/parser.rb b/lib/oxml/parser.rb index 4d09b76..d3d7319 100644 --- a/lib/oxml/parser.rb +++ b/lib/oxml/parser.rb @@ -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) From 148351c39b59c782ad0cfb23ac29d167ebc016ea Mon Sep 17 00:00:00 2001 From: onli Date: Wed, 7 Jan 2026 10:36:09 +0100 Subject: [PATCH 2/3] document changes and version bump --- CHANGELOG.md | 6 ++++++ lib/oxml/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4b0bf..5527fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/oxml/version.rb b/lib/oxml/version.rb index d5b43ea..961b2b6 100644 --- a/lib/oxml/version.rb +++ b/lib/oxml/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module OXML - VERSION = '0.5.1' + VERSION = '0.5.2' end From a75afadba9835cd1d4f94cb1f6cb60cde1fb073d Mon Sep 17 00:00:00 2001 From: onli Date: Wed, 7 Jan 2026 11:12:20 +0100 Subject: [PATCH 3/3] Do not add xsi:nil and do close empty elements Makes XML documents valid that do not declase the xsi namespace and keeps XML structure intact --- lib/oxml/builder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/oxml/builder.rb b/lib/oxml/builder.rb index d57af83..075e3c1 100644 --- a/lib/oxml/builder.rb +++ b/lib/oxml/builder.rb @@ -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)