Skip to content

[WIP] Keep text content in XML round-trip - #530

Closed
suleman-uzair wants to merge 7 commits into
mainfrom
fix/roundtrip_xml_text_missing
Closed

suleman-uzair wants to merge 7 commits into
mainfrom
fix/roundtrip_xml_text_missing

Conversation

@suleman-uzair

Copy link
Copy Markdown
Member

This PR updates the Nokogiri adapter to handle XML entities correctly in ordered and unordered processing.

closes #527

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements XML entity reference preservation in the Nokogiri adapter to enable round-trip XML processing. The changes introduce special handling for XML entity references (like —, ®, &spacer;) so they maintain their original form during parse-serialize cycles, rather than being converted to their Unicode equivalents.

Key Changes

  • Introduced entity node tracking using a special marker (__entity) to distinguish entity references from regular text nodes
  • Added entity-specific methods in the Element class and Nokogiri adapter for detection and serialization
  • Implemented comprehensive test coverage across all three XML adapters (Nokogiri, Oga, Ox) to verify entity handling behavior

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
spec/lutaml/model/entity_spec.rb Adds comprehensive test coverage for entity handling across Nokogiri, Oga, and Ox adapters with mixed, ordered, and default content modes
lib/lutaml/model/xml/element.rb Introduces constants and entity? method to identify entity reference nodes in the element tree
lib/lutaml/model/xml/nokogiri_adapter.rb Implements entity node detection, serialization helpers, and special handling in ordered element building
lib/lutaml/model/xml/document.rb Adds entity-aware text content processing in update_xml_with_entity_and_text method
lib/lutaml/model/xml/builder/nokogiri.rb Adds add_entity method to create Nokogiri EntityReference nodes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Outdated
Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Outdated
Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Outdated
Comment thread lib/lutaml/model/xml/element.rb Outdated
Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Outdated
Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Outdated
Comment thread lib/lutaml/model/xml/element.rb
Comment thread lib/lutaml/model/xml/document.rb Outdated
Comment thread lib/lutaml/model/xml/element.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb
Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb
@suleman-uzair
suleman-uzair force-pushed the fix/import_later_with_register branch from 5539306 to f901d8d Compare December 2, 2025 08:13
@suleman-uzair
suleman-uzair force-pushed the fix/roundtrip_xml_text_missing branch from c11a81d to 2516b5f Compare December 2, 2025 12:01
@suleman-uzair
suleman-uzair force-pushed the fix/import_later_with_register branch 2 times, most recently from ac0c619 to 249fd5e Compare December 4, 2025 07:16
@ronaldtse
ronaldtse deleted the branch main December 5, 2025 04:42
@ronaldtse ronaldtse closed this Dec 5, 2025
@ronaldtse

Copy link
Copy Markdown
Contributor

Not sure why merging #526 closed this? Reopening. @suleman-uzair is this ready? Thanks.

@ronaldtse

Copy link
Copy Markdown
Contributor

Trying to reopen.

@ronaldtse ronaldtse reopened this Dec 5, 2025
@suleman-uzair
suleman-uzair force-pushed the fix/roundtrip_xml_text_missing branch from 829deb3 to 8371976 Compare December 5, 2025 11:18
@suleman-uzair
suleman-uzair changed the base branch from fix/import_later_with_register to main December 5, 2025 11:18
@suleman-uzair suleman-uzair linked an issue Dec 5, 2025 that may be closed by this pull request
@suleman-uzair

Copy link
Copy Markdown
Member Author

is this ready? Thanks.

@ronaldtse No, I'm currently working on the following PR to fix the failing CI checks:

I'll let you know as soon as it's ready.

Comment thread lib/lutaml/model/xml/nokogiri_adapter.rb Fixed
@suleman-uzair suleman-uzair changed the title [WIP] Keep text content in XML round-trip Keep text content in XML round-trip Dec 10, 2025
@suleman-uzair suleman-uzair changed the title Keep text content in XML round-trip [WIP] Keep text content in XML round-trip Dec 12, 2025
ronaldtse added a commit that referenced this pull request Apr 1, 2026
Port PR #530 - Sanitize named HTML entities (like ©, —)
to numeric character references before parsing, since XML parsers
only support the 5 standard XML entities by default.

- Add htmlentities gem dependency
- Add sanitize_xml_for_entities to Document base class
- Use sanitize in NokogiriAdapter and OgaAdapter parse methods
- Add entity handling tests ( entity_spec.rb, nokogiri_adapter_spec.rb)
- Update entity_fragmentation_spec expected Unicode chars
- Update latin_encoding fixture with ⊚ entity
@ronaldtse ronaldtse closed this Apr 1, 2026
@ronaldtse
ronaldtse force-pushed the fix/roundtrip_xml_text_missing branch from 05a6674 to 1694368 Compare April 1, 2026 12:35
ronaldtse added a commit that referenced this pull request Apr 1, 2026
Port PR #530 - Sanitize named HTML entities (like ©, —)
to numeric character references before parsing, since XML parsers
only support the 5 standard XML entities by default.

- Add htmlentities gem dependency
- Add sanitize_xml_for_entities to Document base class
- Use sanitize in NokogiriAdapter and OgaAdapter parse methods
- Add entity handling tests ( entity_spec.rb, nokogiri_adapter_spec.rb)
- Update entity_fragmentation_spec expected Unicode chars
- Update latin_encoding fixture with ⊚ entity
@ronaldtse ronaldtse reopened this Apr 1, 2026
@ronaldtse

Copy link
Copy Markdown
Contributor

This is ported to #593

@ronaldtse
ronaldtse force-pushed the fix/roundtrip_xml_text_missing branch from 2edba74 to 8371976 Compare April 1, 2026 13:34
ronaldtse added a commit that referenced this pull request Apr 3, 2026
Port PR #530 - Sanitize named HTML entities (like ©, —)
to numeric character references before parsing, since XML parsers
only support the 5 standard XML entities by default.

- Add htmlentities gem dependency
- Add sanitize_xml_for_entities to Document base class
- Use sanitize in NokogiriAdapter and OgaAdapter parse methods
- Add entity handling tests ( entity_spec.rb, nokogiri_adapter_spec.rb)
- Update entity_fragmentation_spec expected Unicode chars
- Update latin_encoding fixture with ⊚ entity
@ronaldtse

Copy link
Copy Markdown
Contributor

This is ported to #593

@ronaldtse ronaldtse closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text content not preserved during XML round-trip

5 participants