GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Codegen] Preserve element sequence order when UPA-valid xs:choice branches share non-leading element names · Issue #165 · polyxml/PolyXML

[Codegen] Preserve element sequence order when UPA-valid xs:choice branches share non-leading element names #165

New issue
Copy link
New issue
Copy link
Closed
Closed
[Codegen] Preserve element sequence order when UPA-valid xs:choice branches share non-leading element names#165
Copy link
Labels
bugSomething isn't workingcodegenPolyXML polyglot code generationschema-irSchema parser and PolyXML-IR canonical type graphtarget:goGo code generator targettarget:pythonPython code generator target

Description

@nth-bailey
nth-bailey
opened on Nov 21, 2026
Issue body actions

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.

Activity

  1. nth-bailey
    added
    bugSomething isn't working
    codegenPolyXML polyglot code generation
    schema-irSchema parser and PolyXML-IR canonical type graph
    target:pythonPython code generator target
    target:goGo code generator target
    on Nov 21, 2026
  2. nth-bailey
    added 2 commits that reference this issue on Nov 21, 2026

    fix(schema-ir): resolve substitution group types, prohibited attribut…

    02c0d8f

    chore(release): 0.41.2 [skip ci]

    d6bcdb6
  3. nth-bailey commented on Nov 21, 2026

    @nth-bailey
    nth-bailey
    on Nov 21, 2026
    MemberAuthor
    More actions

    Resolved on main in commits 02c0d8f / 753d2c1 / 8ccbc48 and verified by green CI run https://github.com/polyxml/PolyXML/actions/runs/44864046472 (Documentation 44864046438, CodeQL 44864046071).

  4. nth-bailey
    closed this as completedon Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodegenPolyXML polyglot code generationschema-irSchema parser and PolyXML-IR canonical type graphtarget:goGo code generator targettarget:pythonPython code generator target

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.