[opencms-dev] How to map field of nested choice xsd to property and solrfield?

Mathias Lin mail at mathiaslin.com
Mon Aug 26 10:19:04 CEST 2013


How do you configure a field mapping from a nested xsd, which has choices?

Since it's not clear at what position the certain choice element is, I am
not sure how to configure the mapping.

Furthermore, how do you configure a searchsetting/solrfield for such nested
choice element? Does it also need to be configured in the parent xsd or in
the nested xsd?

The OpenCms documentation unfortunately doesn't give that much info about
those cases.


Below is an article.xsd, which embeds a article-choices.xsd.


    <xsd:complexType name="OpenCmsMAArticle">
        <xsd:sequence>
            <xsd:element name="Title" type="OpenCmsString" minOccurs="1"
maxOccurs="1"/>
            <xsd:element name="Subtitle" type="OpenCmsString" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="Teaser" type="OpenCmsString" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="Text" type="OpenCmsHtml" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="DetailViewPage" type="OpenCmsVfsFile"
minOccurs="0" maxOccurs="1"/>
*            <xsd:element name="OptionalElements"
type="OpenCmsMAArticleChoice" minOccurs="0" maxOccurs="unbounded"/>*
        </xsd:sequence>
        <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
    </xsd:complexType>


    <xsd:complexType name="OpenCmsMAArticleChoice">
        <xsd:choice>
            <xsd:element name="FeaturedImage" type="OpenCmsVfsFile"
minOccurs="0" maxOccurs="1"/>
            <xsd:element name="LandingPageImage" type="OpenCmsVfsFile"
minOccurs="0" maxOccurs="1"/>
            <xsd:element name="Image" type="OpenCmsVfsFile" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="IFrame" type="OpenCmsString" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="Video" type="OpenCmsMAVideo" minOccurs="0"
maxOccurs="1"/>
            <xsd:element name="LeftButton" type="OpenCmsMAButton"
minOccurs="0" maxOccurs="1"/>
            <xsd:element name="RightButton" type="OpenCmsMAButton"
minOccurs="0" maxOccurs="1"/>
            <xsd:element name="ReleaseDate" type="OpenCmsDateTime"
minOccurs="0" maxOccurs="1"/>
        </xsd:choice>
        <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
    </xsd:complexType>


My question now is, how can I map the nested OptionalElements/ReleaseDate
to attribute:datereleased ?

The approach below seems to work for the first mapping of a choice element,
but it doesn't "feel right". Do I really need to configure a mapping for
all the 7 position at which the choice item could be?
Assuming that there can be a maximum of 7 choice elements (number of
elements in my article-choice.xsd), I mapped all of them to the attribute,
which seems to work that OpenCms only takes the

            <mappings>
                <mapping element="Title" mapto="property:Title"/>
                <mapping element="OptionalElements[1]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[2]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[3]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[4]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[5]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[6]/ReleaseDate"
mapto="attribute:datereleased"/>
                <mapping element="OptionalElements[7]/ReleaseDate"
mapto="attribute:datereleased"/>

However, when I want to add further mappings for other choice elements,
this approach doesn't work.


Also, how to map such field to a searchsetting / solrfield? Do I add it to
the parent or the nested xsd? Because using brackets for the [index]
doesn't seem to be valid syntax.

This doesn't work:

<searchsetting element="OptionalElements[2]/FeaturedImage"
searchcontent="true">
    <solrfield targetfield="afeaturedimage" />
</searchsetting>

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130826/45112832/attachment.htm>


More information about the opencms-dev mailing list