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

Content-Definition with XSD: Wrong order for choice elements after XSD change or saving in control code editor #296

Closed
mwxwidmann opened this issue Feb 11, 2015 · 2 comments

Comments

@mwxwidmann
Copy link
Contributor

When a content type definition uses a choice element that has maxOccurs > 1, then the "correctXmlStructure" functionality that is triggered by XSD changes or when the XML control code is edited and saved in OpenCms is causing a faulty ordering of child elements.

Simplified parent XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
    <xsd:include schemaLocation="opencms://system/modules/com.mediaworx.weisseliste.opencms.formgenerator/schemas/nested/formFields.xsd"/>

    <xsd:element name="Forms" type="OpenCmsForms"/>

    <xsd:complexType name="OpenCmsForms">
        <xsd:sequence>
            <xsd:element name="Form" type="OpenCmsForm" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="OpenCmsForm">
        <xsd:sequence>
            <xsd:element name="Title" type="OpenCmsString" />
            <xsd:element name="FormFields" type="OpenCmsFormFields" minOccurs="0"/>
            <xsd:element name="SubmitText" type="OpenCmsString" />
        </xsd:sequence>
        <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
    </xsd:complexType>

    <xsd:annotation>
        <xsd:appinfo>
        </xsd:appinfo>
    </xsd:annotation>
</xsd:schema>

Spimplified child XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>

<xsd:element name="FormFieldss" type="OpenCmsFormFieldss"/>

<xsd:complexType name="OpenCmsFormFieldss">
    <xsd:sequence>
        <xsd:element name="FormFields" type="OpenCmsFormFields" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="OpenCmsFormFields">
    <xsd:choice minOccurs="0" maxOccurs="1000">
        <xsd:element name="Input" type="OpenCmsString" minOccurs="0"/>
        <xsd:element name="Select" type="OpenCmsString" minOccurs="0"/>
        <xsd:element name="Radio" type="OpenCmsString" minOccurs="0"/>
    </xsd:choice>
    <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
</xsd:complexType>

<xsd:annotation>
    <xsd:appinfo>
    </xsd:appinfo>
</xsd:annotation>
</xsd:schema>

When the content type definition is changed and the content is edited again or when the XML control code of the content is edited and saved, the Method A-CmsXmlDocument.correctXmlStructure is triggered. And here's what happens:

Order of the form fields before correctXmlStructure:

  • Select 1
  • Input 1
  • Input 2
  • Radio 1
  • Input 3
  • Select 2
  • Radio 2

Order of the form fields after correctXmlStructure:

  • Input 1
  • Input 2
  • Input 3
  • Select 1
  • Select 2
  • Radio 1
  • Radio 2

So correctXmlStructure sorts the fields by type in the order of the choice definition. This is unexpected behaviour and it breaks the content every time the content type xsd is changed (or the control code is edited and saved).

@mwxwidmann mwxwidmann changed the title Content-Definition with XSD: Wrong order for choice elements after xsd change or saving in source code editor Content-Definition with XSD: Wrong order for choice elements after XSD change or saving in control code editor Feb 11, 2015
mwxwidmann added a commit to mediaworx/opencms-core that referenced this issue Feb 11, 2015
…or choice elements after XSD change or saving in control code editor)
@aKandzior
Copy link
Member

This is ok in general but keep in mind to remove items from the choice list XML in case the choice definition is removed.

A test case would be great. Existing test class for XML content schema modifications is:

test/org.opencms.xml.content.TestCmsXmlContentSchemaModifications

mwxwidmann added a commit to mediaworx/opencms-core that referenced this issue Feb 11, 2015
aKandzior added a commit that referenced this issue Feb 27, 2015
Merged fix for issue #296 - Content-Definition with XSD: Wrong order for choice elements after XSD change or saving in control code editor (Improved)
@aKandzior
Copy link
Member

Closed as the PR for this has been merged into the core.

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

No branches or pull requests

2 participants