Summary
When a deterministic (UPA-valid) <xs:choice> contains multiple <xs:sequence> branches whose leading elements differ (satisfying W3C UPA) but whose non-leading elements share a name—for example (ok, detail) vs (err, detail)—flattening the choice fields onto the parent struct deduplicates detail at its first appearance ([ok, detail, err]).
Because serialized element emission iterates in struct field order (ok, detail, err), serializing the second branch (err + detail) writes <detail> before <err>, violating the schema content model (?:ok;detail;|err;detail;) in generated Go MarshalXML and Python validators.
Upstream references: mganss/XmlSchemaClassGenerator#592 (mganss/XmlSchemaClassGenerator#592), mganss/XmlSchemaClassGenerator#593 (mganss/XmlSchemaClassGenerator#593), tefra/xsdata#1206 (tefra/xsdata#1206), and tefra/xsdata#1216 (tefra/xsdata#1216).
Minimal Reproducer (tests/fixtures/conformance/wave9/choice_shared_tail.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Response">
<xs:choice>
<xs:sequence>
<xs:element name="ok" type="xs:string"/>
<xs:element name="detail" type="xs:string"/>
</xs:sequence>
<xs:sequence>
<xs:element name="err" type="xs:string"/>
<xs:element name="detail" type="xs:string"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:schema>
Verified with polyxml generate choice_shared_tail.xsd --lang go + go test:
type Response struct {
XMLName xml.Name `json:"-"`
Ok *string `xml:"ok,omitempty" json:"ok,omitempty"`
Detail *string `xml:"detail,omitempty" json:"detail,omitempty"`
Err *string `xml:"err,omitempty" json:"err,omitempty"`
}
Serializing Response{Err: &e, Detail: &d} emits <detail> before <err>, failing polyxmlValidateContent against ^(?:(?:ok;detail;|err;detail;))$:
Marshal branch 2 failed: content model constraint violated.
Expected Behavior
For <xs:choice> compositors whose branches are <xs:sequence> groups sharing element names:
- Either model each sequence branch cleanly (e.g. typed branch helpers / union representation) or preserve topological partial ordering across branches (emitting
detail after both ok and err when branches agree on relative order), and ensure serialized order passes the generated content-model regex across Go, Python, Rust, C#, Java, C++20, and TypeScript.