-
Notifications
You must be signed in to change notification settings - Fork 25
Generated serializer unconditionally emits xmlns:xsi on root element #256
Description
When NILLABLE_TYPE_SUPPORT is enabled, every generated root-element serializer emits xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" unconditionally, even when no xsi:nil or xsi:type attributes exist in the document being serialized.
Where
xsd-parser/src/pipeline/renderer/steps/quick_xml/serialize.rs, the NamespaceSerialization::Global branch (lines 731-797).
The codegen decides at code generation time whether to emit xsi based on the generator flag:
let need_xsi_namespace =
nillable_type_support && !collector.provides_xsi_namespace();This generates code that unconditionally writes xsi on every root element:
if self.is_root {
helper.write_xmlns(
&mut bytes,
Some(&super::super::PREFIX_XSI),
&super::super::NS_XSI,
);
}There is no runtime check for whether any nillable field actually contains a nil value in the current document instance.
Effect
Serialized output includes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" on the root element even when:
- The schema has no
nillable="true"elements at all - The schema has nillable elements but the current instance has no nil values
This pollutes the namespace context for all descendant elements. In particular, xs:any content deserialized as Element captures all in-scope namespaces via helper.namespaces(). After a serialize/deserialize round-trip, extension elements gain an xsi namespace entry that was not present in the original document, breaking equality.
Expected behavior
The xsi namespace should only be emitted when the serialized output actually contains xsi:nil or xsi:type attributes.
Workaround
For schemas that have no nillable elements, remove the flag:
generator_flags.remove(GeneratorFlags::NILLABLE_TYPE_SUPPORT);Metadata
Metadata
Assignees
Labels
Projects
Status