charto / cxsd

Streaming XSD parser and XML parser generator with TypeScript output
MIT License
111 stars 55 forks source link

parsing choice sequence loses element ordering #29

Open martaver opened 5 years ago

martaver commented 5 years ago

Trying to parse an XML file with a schema that contains a choice sequence:

      <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="Title" type="xs:string" />
        <xs:element name="Subtitle" type="xs:string" />
        <xs:element name="Html" type="xs:string" />
        <xs:element name="Vimeo" type="VimeoPart" />
        <xs:element name="Youtube" type="YoutubePart" />
        <xs:element name="Soundcloud" type="SoundcloudPart" />
        <xs:element name="Image" type="ImagePart" />
        <xs:element name="Link" type="LinkPart" />
      </xs:choice>

The above generates the following in a type:

        Html: string[];
    Image: ImagePart[];
    Link: LinkPart[];
    Soundcloud: SoundcloudPart[];
    Subtitle: string[];
    Title: string[];
    Vimeo: VimeoPart[];
    Youtube: YoutubePart[];

However, this structure loses the ordering of the elements. In my case, order is important because it contains site content.

I would have expected the following types, perhaps:

choices: (Html | Image | Link | Soundcloud | Subtitle | Title | Vimeo | Youtube)[]
FranklinChen commented 4 years ago

Unfortunately, I noticed this severe limitation several months ago when looking for a data binding tool for TypeScript. I never did find a suitable one comparable to, say, Java JAXB. Also, I think this project has been abandoned. There was mention of a rewrite of cxml but I never heard back about its status: https://github.com/charto/cxml/issues/15

martaver commented 4 years ago

Is there really no comprehensive xsd/xml parser/writer for typescript out there?

On Wed, 27 Nov 2019 at 12:14, Franklin Chen notifications@github.com wrote:

Unfortunately, I noticed this severe limitation several months ago when looking for a data binding tool for TypeScript. I never did find a suitable one comparable to, say, Java JAXB. Also, I think this project has been abandoned. There was mention of a rewrite of cxml but I never heard back about its status: charto/cxml#15 https://github.com/charto/cxml/issues/15

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/charto/cxsd/issues/29?email_source=notifications&email_token=ABOXAMTGLUGDVA4U46J576DQVXQZNA5CNFSM4JRZHH5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFIEPZA#issuecomment-558909412, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOXAMTVH6WTFQ3QWHWWI3LQVXQZNANCNFSM4JRZHH5A .