Skip to content

[maven-4.0.x] Fix consumer POM serialization of prefixed XML attributes (fixes #11760)#12110

Merged
gnodet merged 2 commits into
maven-4.0.xfrom
backport/maven-4.0.x/pr-11823
May 19, 2026
Merged

[maven-4.0.x] Fix consumer POM serialization of prefixed XML attributes (fixes #11760)#12110
gnodet merged 2 commits into
maven-4.0.xfrom
backport/maven-4.0.x/pr-11823

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented May 19, 2026

Summary

Backport of #11823 to maven-4.0.x.

Fix consumer POM serialization so that prefixed attributes (like mvn:combine.children) produce valid XML even when the namespace declaration (xmlns:mvn) was on an ancestor element not part of the Maven model.

Fixes #11760

Changes

  • Add XmlNode.namespaces() returning inherited prefix-to-URI bindings
  • Accumulate and propagate namespace context during parsing in DefaultXmlService
  • Fix writer-stax.vm and writer.vm to resolve and declare namespaces properly
  • Preserve dominant node's namespace context during merge
  • Add 28 tests covering parsing, writing, merging, and consumer POM simulation

Claude Code on behalf of Guillaume Nodet

During consumer POM transformation, namespace declarations like xmlns:mvn on
<project> are lost (not part of the Maven model), but prefixed attributes like
mvn:combine.children on XmlNode configuration trees survive, producing invalid
XML with undeclared namespace prefixes.

Fix by adding namespace context tracking to XmlNode: the parser now accumulates
namespace declarations and propagates them to child nodes. The StAX and XPP3
writers resolve prefixed attributes against local declarations first, then the
inherited namespace context, auto-declaring namespaces as needed. Orphaned
prefixes (no declaration, no context) are stripped as a last resort to ensure
valid XML output.

Changes:
- Add XmlNode.namespaces() returning inherited prefix-to-URI bindings
- Accumulate and propagate namespace context during parsing in DefaultXmlService
- Fix writer-stax.vm and writer.vm to resolve and declare namespaces properly
- Preserve dominant node's namespace context during merge
- Add 28 tests covering parsing, writing, merging, and consumer POM simulation
@gnodet gnodet added this to the 4.0.0-rc-6 milestone May 19, 2026
…eStrategyTest

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet merged commit 7a9947b into maven-4.0.x May 19, 2026
23 checks passed
@gnodet gnodet deleted the backport/maven-4.0.x/pr-11823 branch May 19, 2026 21:46
@github-actions
Copy link
Copy Markdown

@gnodet Please assign appropriate label to PR according to the type of change.

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.

1 participant