[opencms-dev] XSD contents : minOccurs maxOccurs problems

Bozidar Ilievski bozidar.ilievski at netcetera.com.mk
Tue May 6 10:18:58 CEST 2008


Hi.

Territorio Jordan-V. wrote:
> Hi,
> 
> I try to make a schemas for editing some blocks of informations, with: a 
> title, a text and an image. So i created a xsd schemas to be able to 
> create structured as I want. Here is my info_article.xsd :
> 
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>     elementFormDefault="qualified">
> 
>     <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd" />
> 
>     <xsd:element name="MyNews" type="OpenCmsMyNews" />
> 
>     <xsd:complexType name="OpenCmsMyNews">
>         <xsd:sequence>
>             <xsd:element name="MyNew" type="OpenCmsMyNew"
>                 minOccurs="0" maxOccurs="unbounded" />
>         </xsd:sequence>
>     </xsd:complexType>
> 
>     <xsd:complexType name="OpenCmsMyNew">
>         <xsd:sequence minOccurs="0" maxOccurs="unbounded">
>             <xsd:element name="Title" type="OpenCmsString" />
>             <xsd:element name="Image" type="OpenCmsVfsFile"
>                 minOccurs="0" maxOccurs="1" />
>             <xsd:element name="Text" type="OpenCmsHtml"/>
>             <xsd:element name="Image" type="OpenCmsVfsFile"
>                 minOccurs="0" maxOccurs="1" />
>         </xsd:sequence>
>         <xsd:attribute name="language" type="OpenCmsLocale"
>             use="required" />
>     </xsd:complexType>
> 
>     <xsd:annotation>
>         <xsd:appinfo>
>             <mappings>
>                 <mapping element="Title" mapto="property:Title" />
>             </mappings>
>             <layouts>
>                 <layout element="Image" widget="ImageGalleryWidget" />
>             </layouts>
>         </xsd:appinfo>
>     </xsd:annotation>
> </xsd:schema>
> 
> The problem is when I edit news pages, the Editor just show one block 
> "OpenCmsMyNew" and I can't build an other... If I modify the code in 
> this way :
> <xsd:element name="Text" type="OpenCmsHtml" minOccurs="0" 
> maxOccurs="unbounded"/>
> I'm able to create as many paragraph as i want, but i cant do the same 
> thing with the "MyNew" block...
> 
> Is there somebody to help ?

You can have one OpenCmsMyNew for every language you define in the 
system. That is how XSD resource types work in OpenCms.

If you want to have 0..unbound OpenCmsMyNew for one language, you need 
to define new resource type, and in it you reference this one.
Example:

...
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd" />
<!-- INCLUDE your OpenCmsMyNew XSD file here -->

<xsd:element name="MyNewsLists" type="OpenCmsMyNewsLists" />

<xsd:complexType name="OpenCmsMyNewsLists">
    <xsd:sequence>
        <xsd:element name="MyNewsList" type="OpenCmsMyNewsList"
            minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="OpenCmsMyNewsList">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
        <xsd:element name="News" type="OpenCmsMyNew" minOccurs="0" 
maxOccurs="1" />
    </xsd:sequence>
    <xsd:attribute name="language" type="OpenCmsLocale"
        use="required" />
</xsd:complexType>
...

> Anyway, someone could tell me why this is forbidden :
> <xsd:complexType name="OpenCmsMyNews">
>         <xsd:sequence>
>              <xsd:element name="Title" type="OpenCmsString" /> <!-- a 
> main title and an introduction before displaying news -->
>              <xsd:element name="Text" type="OpenCmsHtml"/>
>             <xsd:element name="MyNew" type="OpenCmsMyNew"
>                 minOccurs="0" maxOccurs="unbounded" />
>         </xsd:sequence>
>     </xsd:complexType>
> 
>     <xsd:complexType name="OpenCmsMyNew">
>         <xsd:sequence minOccurs="0" maxOccurs="unbounded">
>             <xsd:element name="Title" type="OpenCmsString" />
>             <xsd:element name="Image" type="OpenCmsVfsFile"
>                 minOccurs="0" maxOccurs="1" />
>             <xsd:element name="Text" type="OpenCmsHtml"/>
>             <xsd:element name="Image" type="OpenCmsVfsFile"
>                 minOccurs="0" maxOccurs="1" />
>         </xsd:sequence>
>         <xsd:attribute name="language" type="OpenCmsLocale"
>             use="required" />
>     </xsd:complexType>
> 
> thank you all
> 
Yes, that is forbidden.
You first define complex type that ends with 's'.
This type consists of 0..unbound elements that are of type with the same 
name, without the last 's'.
This second type can have sequence of other elements, and it must have 
language attribute.

Regards,
Bobi.

-- 
Bozidar Ilievski | bozidar.ilievski at netcetera.com.mk
phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495
Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk



More information about the opencms-dev mailing list