The structure of content is defined in XML schema definitions. In this topic we discuss how you can structure your content. We are concerned only with the structure for one language. Information on the more general multi-language structure you find in the related links.
In essence, the structure of the content is given by the elements of the schema type. Such elements themselves can:
In the end, each "leave" in the content's structure must be of a basic schema type that is provided by OpenCms. In this topic you learn how to structure your content correctly.
The structure of the schema type reflects the structure of your content. For a schema that is used to define a content type, the structure always is a sequence of elements followed by a language attribute:
<xsd:complexType name="OpenCmsBootstrapBlog">
<xsd:sequence>
<xsd:element name="Title" type="OpenCmsString" />
<xsd:element name="Date" type="OpenCmsDateTime" />
<xsd:element name="Teaser" type="OpenCmsString" minOccurs="0" />
<xsd:element name="Paragraph" type="OpenCmsBootstrapParagraph" maxOccurs="5" />
<xsd:element name="Category" type="OpenCmsCategory" minOccurs="0" />
<xsd:element name="Author" type="OpenCmsString" />
<xsd:element name="AuthorMail" type="OpenCmsString" minOccurs="0" />
<xsd:element name="Availability" type="OpenCmsBootstrapAvailability" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="language" type="OpenCmsLocale" use="required" />
</xsd:complexType>
Each schema element has a name
and a type
attribute, optionally minOccurs
and maxOccurs
can be set. If not given, minOccurs
and maxOccurs
default to 1.
By setting minOccurs
and maxOccurs
, you can make schema elements optional or allow them to occur multiple times:
minOccurs="0"
makes a schema element optional in any XML content that complies with the schema.minOccurs="{minNum}"
and maxOccurs="{maxNum}"
specifies that the schema element must occur at least {minNum}
times and at most {maxNum}
times in any XML content that complies with the schema. Thus you can allow or force multiple occurrences of schema elements in sequence.The types set in the type
attribute of the <xsd:element>
nodes must be defined when they are used. Allowed types are:
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
in your XSD (see here). These types are so-called basic schema types. They store content like HTML, Strings, Links, Images or Boolean values and for these types (several) special editor widgets exist.In the above example, the schema defines that each content that that complies to the schema has:
Title
node with a value of type OpenCmsString
followed by,Date
node with a value of type OpenCmsTimeDate
followed by,Teaser
node (i.e., the node can also be missing) of type OpenCmsString
followed by,Paragraph
nodes of type OpenCmsBootstrapParagraph
, which is a nested content defined by another schema (i.e., which has sub-nodes as defined in the separate schema) followed by,Category
node of type OpenCmsCategory
followed by,Here's how a content that complies to the above structure can look like:
<?xml version="1.0" encoding="UTF-8"?>
<BootstrapBlogs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="opencms://system/modules/com.alkacon.bootstrap.schemas/schemas/blog.xsd">
<BootstrapBlog language="en">
<Title><![CDATA[OpenCms is intuitive]]></Title>
<Date>1400763600000</Date>
<Paragraph>
<Text name="Text0">
<links/>
<content><![CDATA[<p>At vero eos ...</p>]]></content>
</Text>
<Image>
<Image>
<link type="WEAK">
<target><![CDATA[/sites/default/.galleries/samples/11.jpg]]></target>
<uuid>c6d9d552-4705-11e3-8417-000c29d28104</uuid>
</link>
</Image>
<Title><![CDATA[Vanilla]]></Title>
</Image>
</Paragraph>
<Author><![CDATA[Jay Pritchett]]></Author>
</BootstrapBlog>
</BootstrapBlogs>
The interesting part is wrapped in the <BootrapBlog language="en">
node. The surrounding structure is caused by the multi-language support. In the example we have the following schema element sequence:
Title
Date
Paragraph
Author
This is kind of the minimal sequence we can have. All optional schema elements are missing and each element that could occur more than once doesn't. Note that the Paragraph
node has many subnodes as defined in the schema of the nested content (that is not given here).
In schemas that define the structure of nested contents, the part defining the nested content's structure can look very similar to that schema part for root contents. The only differences are:
required
should be set to optional
.<xsd:sequence>
you can use <xsd:choice>
to define alternative nodes. Read more about alternatives here.OpenCms provides a set of basic schema types that are exposed via the opencms-xmlcontent.xsd
. All of your leave elements have to be of such a basic schema type. These schema types are used to store atomic dataSome of the basic types have an internal structure, but when using them in the system, they behave like an atomic unit.. There are types for strings, booleans, dates, but also for links, images, categories, etc. Here's a list of the available basic schema types.
Stores a Boolean value, i.e., true
or false
.
Stores multiple categories
Stores a color value
Stores strings with HTML markup. In particular, it extracts links in HTML and adjusts (internal) links with the link substitution manager, such that for example also exported VFS resources are found. Furthermore, for links to VFS resources the link relationship engine is used - thus they are also correctly found when they moved.
Stores the name of a locale, e.g., "en" or "de".
Stores arbitrary strings and stripes away HTML markup when indexing the value for search.
Stores arbitrary strings and does not further manipulate them.
Stores a time stamp as long int
.
Stores internal and external links.
Stores links to VFS resources, i.e., internal links.
Stores links to an image and serveral extra information on the image. It is not necessary to use this type for images - unless you want all the extra information. You can also use OpenCmsVfsFile
. Check the description of the image widgets (VfsImageWidget and ImageGalleryWidget) for further information.