Skip to content

asXml(): emit formatting line breaks only where the document contains whitespace#1158

Merged
rbri merged 3 commits into
HtmlUnit:masterfrom
shapiroronny:asxml-ws-fix
Jul 14, 2026
Merged

asXml(): emit formatting line breaks only where the document contains whitespace#1158
rbri merged 3 commits into
HtmlUnit:masterfrom
shapiroronny:asxml-ws-fix

Conversation

@shapiroronny

Copy link
Copy Markdown
Contributor

asXml() inserted a line break and indentation at every element boundary. When two elements were adjacent in the source with no whitespace between them, that break was not part of the document, and after a parse round-trip it renders as a visible space between inline elements — e.g. <span>a</span><span>b</span> came back as "a b".

DomElement.printXml() no longer forces a break before the first child or before the following sibling. A whitespace-only text node now marks where a formatting break belongs (DomText.printXml() sets the flag instead of dropping the node), so the output follows the whitespace actually present in the document: adjacent elements stay adjacent, and breaks appear only where the source had whitespace.

Documents whose elements are already separated by whitespace — the common case — serialize as before. Verified against every asXml()-referencing test class (1736 test runs) and CodeStyleTest, all green.

shapiroronny and others added 3 commits July 14, 2026 16:57
… whitespace

Adjacent elements without whitespace in between no longer gain a fabricated
line break, which rendered as a visible space between inline elements after a
parse round-trip. Whitespace-only text nodes now mark where the formatting
break belongs instead of being silently dropped, so the output follows the
whitespace actually present in the document.
@rbri rbri merged commit 05ab2b1 into HtmlUnit:master Jul 14, 2026
5 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@rbri

rbri commented Jul 14, 2026

Copy link
Copy Markdown
Member

@shapiroronny thanks (as always), have done a bit more hacking on this topic. Please have a look and provide feedback. Maybe there is more room for improvements for the output.

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.

2 participants