Fix ElementSerializer producing invalid xmlns:= and duplicate namespace declarations#255
Merged
Bergmann89 merged 1 commit intoBergmann89:masterfrom Mar 16, 2026
Conversation
34e56e9 to
4725555
Compare
Owner
|
Hey @rcbevans, Thanks for providing this fix. I have limited time this week, so it may take me until the weekend to complete the review. |
…ations in ElementSerializer Normalize empty namespace prefix to None in both ElementSerializer and SerializeHelper::write_xmlns so the default namespace (xmlns=) is correctly recognized regardless of whether it was registered by generated code (None) or from Element::namespaces (empty byte slice). Filter xmlns attributes from Element::attributes during serialization when a corresponding entry exists in Element::namespaces, preventing double emission. Attributes added only via .attribute() without a matching .namespace() entry are preserved.
4725555 to
eed96f8
Compare
Bergmann89
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #254
Key changes
SerializeHelper::write_xmlns(xsd-parser-types/src/quick_xml/serialize.rs):Some(NamespacePrefix(""))toNoneat the top ofwrite_xmlns, so the default namespace is correctly matched regardless of whether it was registered by generated code (None) or fromElement::namespaces(empty byte slice). This also preventsadd_namespace_entryfrom producing the invalidxmlns:attribute name.ElementSerializer::next_item(xsd-parser-types/src/xml/element.rs):Nonebefore callingwrite_xmlnsin the namespaces loopelement.attributeswhen a corresponding entry exists inelement.namespaces, preventing double emission. Attributes added only via.attribute()without a matching.namespace()entry are preserved.Tests added
roundtrip_with_default_namespaceroundtrip_without_namespacesroundtrip_with_prefixed_namespace_onlyroundtrip_default_namespace_undeclarationxmlns=""undeclares default namespace (XML Namespaces 1.0 §6.2)roundtrip_prefix_rebindingroundtrip_inherited_namespace_not_redeclaredattribute_only_xmlns_is_preserved.attribute()only (no.namespace()) preservedVerification
cargo test -p xsd-parser-types --features quick-xml --lib xml::element::tests