Skip to content

Add promote_namespaces function#103

Open
veewee wants to merge 1 commit into4.xfrom
feature/promote-namespaces
Open

Add promote_namespaces function#103
veewee wants to merge 1 commit into4.xfrom
feature/promote-namespaces

Conversation

@veewee
Copy link
Copy Markdown
Owner

@veewee veewee commented Mar 30, 2026

Summary

  • Adds promote_namespaces as both a Manipulator and Configurator
  • Moves prefixed namespace declarations (xmlns:foo="...") from child elements to the document root, preserving original prefix names
  • Handles conflicts: if the same prefix maps to different URIs, the first in document order is promoted; subsequent conflicting declarations are left in place
  • Default namespace declarations (xmlns="...") are not promoted

Unlike optimize_namespaces, this does not rename prefixes.

Context

Some SOAP servers (e.g. Microsoft Business Central) run XSD validation that requires namespace declarations on the envelope element, not scattered on child elements. The XML is semantically identical, but their validation rejects inline declarations.

Ref: php-soap/encoding#48

Test plan

  • 13 manipulator test cases covering: no-op, already on root, child-to-root, duplicates, mixed namespaces, root-vs-child conflict, child-vs-child conflict, deep nesting, default namespace, empty namespace, namespaced attributes, and a realistic SOAP envelope
  • 4 configurator test cases verifying the wrapper works during Document::fromXmlString()
  • Full test suite passes (688 tests)
  • Psalm passes with no errors

Moves prefixed namespace declarations from child elements to the
document root element while preserving original prefix names. Unlike
optimize_namespaces, this does not rename prefixes.

This is useful when dealing with servers that require all namespace
declarations on the root element (e.g. SOAP servers doing XSD
validation).

Ref: php-soap/encoding#48
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