Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sequence numbering in choice with sequences with complexTypes #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

larshesel
Copy link

@larshesel larshesel commented Jan 10, 2025

The sequence numbering was reset within the complexType handling and this change attempts to preserve the sequence numbering across the elements in the choice alternative handling.

Hi @willemdj this PR fixes #96 and all tests passes, including the new one I added.

First I fixed it by reverting this change 42dc8c9#diff-9669fbc4324a63d6d211486aeef2f42b2fb749159b449a5f2aae44ab5c9f0930R520 so translateLocalComplexType/2 wouldn't reset the seqCnt - @devinus do you know why this change was introduced? With the seqCnt reset removed all tests still pass.

In any case I came across the TODO (removed in the commit) and it made sense to me and I changed the code to preserve the count across elements and reset it when recursing.

What do you think?

Kind regards,
Lars

The sequence numbering was reset within the complexType handling and
this change attempts to preserve the sequence numbering across the
elements in the choice alternative handling.
@willemdj
Copy link
Owner

You are probably on the right track...
But, I have a fairly large set of tests (outside of the repo), and this breaks at least 2 of them. (Possibly a third, but that one is quite large and I didn't look into it in detail.) Could you have a look at that?

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="element1" type="xsd:string"/>
                <xsd:element name="element3" type="xsd:string"/>
                <xsd:sequence>
                    <xsd:element name="element4" type="xsd:string"/>
                    <xsd:element name="element5" type="xsd:string"/>
                </xsd:sequence>
                <xsd:sequence minOccurs="0">
                    <xsd:element name="element6" type="xsd:string"/>
                    <xsd:element name="element7" type="xsd:string"/>
                </xsd:sequence>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

XML:

<?xml version="1.0"?>
<root>
    <element1>Value 1</element1>
    <element3>Value 3</element3>
    <element4>Value 4</element4>
    <element5>Value 5</element5>
</root>

XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="element1.1" type="xsd:string"/>
                <xsd:element name="element1.2" type="xsd:string"/>
                <xsd:sequence>
                    <xsd:element name="element1.3.1" type="xsd:string"/>
                    <xsd:element name="element1.3.2" type="xsd:string"/>
                </xsd:sequence>
                <xsd:sequence>
                    <xsd:sequence minOccurs = "2" maxOccurs="5">
                           <xsd:element name="element1.4.1.1" type="xsd:string"/>
                           <xsd:element name="element1.4.1.2" type="xsd:string"/>
                    </xsd:sequence>
                    <xsd:element name="element1.4.2" type="xsd:string"/>
                    <xsd:element name="element1.4.3" type="xsd:string"/>
                </xsd:sequence>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

XML:

<?xml version="1.0"?>
<root>
    <element1.1>Value 1</element1.1>
    <element1.2>Value 3</element1.2>
    <element1.3.1>Value 4</element1.3.1>
    <element1.3.2>Value 4</element1.3.2>
    <element1.4.1.1>Value 4</element1.4.1.1>
    <element1.4.1.2>Value 4</element1.4.1.2>
    <element1.4.1.1>Value 4</element1.4.1.1>
    <element1.4.1.2>Value 4</element1.4.1.2>
    <element1.4.2>Value 5</element1.4.2>
    <element1.4.3>Value 5</element1.4.3>
</root>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected event, expected end-tag
2 participants