[opencms-dev] XML-Content xsd:choice

patric dosch patric.dosch at virtual-identity.com
Wed Sep 28 14:35:17 CEST 2011


The error I unfortunately do not know, but my example is from a current project. 

And your language-node should be required in the test-schema.

 

Regards, Patric

 

Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Thomas Göttlich
Gesendet: Mittwoch, 28. September 2011 13:20
An: The OpenCms mailing list
Betreff: Re: [opencms-dev] XML-Content xsd:choice

 

Hi Patric,

thanks for the advice.

Does that mean I have to use an intermediate schema to define the choice?

Currently, I have this:

test.xsd    //my example below shows the complexType definition
module1.xsd  //a simple opencms schema to define a sub-module
module2.xsd  //another simple opencms schema to define a sub-module

So what I want to do is to have a list of "modules" (or elements) in the test files where the modules can be of one of those two types.

Creating another complextType in the test.xsd schema like the following, results in the error "Exactly 2 complex type definitions are required, not 3."

 <!-- 3. Root element name and type of our XML type -->
  <xsd:element name="Tests" type="OpenCmsTests"/>

  <!-- 4. Definition of the type described above -->
  <xsd:complexType name="OpenCmsTests">
    <xsd:sequence>
      <xsd:element name="Test" type="OpenCmsTest"
        minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>
    
  <!-- 5. Data field definitions -->
  <xsd:complexType name="OpenCmsTest">
    <xsd:sequence>
      <!-- 
        <xsd:element name="MT1" type="OpenCmsModule1" minOccurs="0" />
        <xsd:element name="MT2" type="OpenCmsModule2" minOccurs="0"  />
       -->
       <xsd:element name="Text" type="OpenCmsText"
          minOccurs="0"/>            
    </xsd:sequence>
    
    <!-- 6. locale attribute is required -->
    <xsd:attribute name="language" type="OpenCmsLocale"
      use="optional"/>
  </xsd:complexType>
  
  <xsd:complexType name="OpenCmsText">   
    <xsd:choice>    
      <xsd:element name="Headline" type="OpenCmsString" minOccurs="0" />
       <xsd:element name="Title" type="OpenCmsString" minOccurs="0" />   
    </xsd:choice>
    
    <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>    
  </xsd:complexType>

Note that the names are just arbitrary chosen, in order to do some tests.

Should the structure instead be like this?

test.xsd    //this would contain a list of the type defined by modulechoice.xsd
modulechoice.xsd //would only contain the element with the xsd:choice between the modules
module1.xsd  //a simple opencms schema to define a sub-module
module2.xsd  //another simple opencms schema to define a sub-module


Thanks for your effort.


Regards,

Thomas

2011/9/28 patric dosch <patric.dosch at virtual-identity.com>

Hey, 

 

You have to make the choice-element in your own schema. 

 

<xsd:complexType name="OpenCmsArticle">

<xsd:sequence>

<xsd:element name="Title" type="OpenCmsString"/> 

[...] 

<xsd:element name="ContextTeaser" type="OpenCmsContextTeaser" minOccurs="0" maxOccurs="unbounded"/>

</xsd:sequence>

<xsd:attribute name="language" type="OpenCmsLocale" use="required"/>

</xsd:complexType>

 

<xsd:complexType name="OpenCmsContextTeaser">

<xsd:choice>

<xsd:element name="TextTeaser" type="OpenCmsTextTeaser" minOccurs="0"/>

<xsd:element name="LinkListTeaser" type="OpenCmsLinkListTeaser" minOccurs="0"/> 

<xsd:element name="Contact" type="OpenCmsVfsFile" minOccurs="0"/>

</xsd:choice>

<xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>

</xsd:complexType>

 

Regards, Patric

 

Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Thomas Göttlich
Gesendet: Mittwoch, 28. September 2011 11:55
An: The OpenCms mailing list
Betreff: [opencms-dev] XML-Content xsd:choice

 

Hi, 

how would I use the xsd:choice element in my schemas?

Currently I tried the following but I get "invalid schema structure" errors:


<xsd:complexType name="OpenCmsTest">
    <xsd:sequence>
      <xsd:choice>
      <!-- 
        <xsd:element name="MT1" type="OpenCmsModule1" minOccurs="0" />
        <xsd:element name="MT2" type="OpenCmsModule2" minOccurs="0"  />
       -->
       <xsd:element name="Headline" type="OpenCmsString"
          minOccurs="1" maxOccurs="1" />
       <xsd:element name="Title" type="OpenCmsString"
        minOccurs="1" maxOccurs="1" />
      </xsd:choice>
    </xsd:sequence>
    
    <!-- 6. locale attribute is required -->
    <xsd:attribute name="language" type="OpenCmsLocale"
      use="optional"/>
  </xsd:complexType>

Unfortunately I did find any documentation or examples, just notes that it is now possible to use that.

Thanks in advance,

Thomas


_____________________________________________________________________

Vorstand: Ralf Heller, Udo Möbes 
Vorsitzende des Aufsichtsrates: Kirsten Heller 
Sitz der Gesellschaft: Gruenwaelderstrasse 10-14, D-79098 Freiburg 
Amtsgericht Freiburg HRB 6218

Versand am 28.09.2011 12:30 von dosch patric
Validation-Code: 4055011134176



_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110928/679543bc/attachment.htm>


More information about the opencms-dev mailing list