XMLContent

From OpenCms Wiki
Revision as of 20:00, 22 November 2006 by Cschoenfeld (Talk | contribs)
Jump to: navigation, search

Contents

Data Types

When creating XML contents, different data types can be used according to the requirements of the desired content. To each data type, a default widget is mapped which creates the input element (e.g. a text input field) for the form based XML content editor.

OpenCms provides the following data types for XML contents:

Widgets

Widgets are used to create a suitable content editor for XML content. The widgets to be used are defined in the XML Schema Definition of your XML content type.

Basic OpenCms XML Schema Definition (opencms-xmlcontent.xsd)

Below you find a copy of the basic XML Schema used by all XMLContent Schemas you define. It is referenced by your custom XMLContent Schema Definition files like this:

<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>

The OpenCms XML system has a custom schema location resolver which knows what to return when this schemaLocation is referenced.

This file actually does not to exist physically in the OpenCms distribution. However, someone found out what it should look like. (See this opencms-dev thread for more information).

   <?xml version="1.0" encoding="UTF-8"?>
   <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       elementFormDefault="qualified">
       <xsd:complexType name="OpenCmsHtml">
           <xsd:sequence>
               <xsd:element name="links" type="OpenCmsLinkTable" />
               <xsd:element name="content" type="OpenCmsHtmlContent" />
           </xsd:sequence>
           <xsd:attribute name="name" type="xsd:string" use="optional" />
           <xsd:attribute name="enabled" type="xsd:boolean" use="optional" />
       </xsd:complexType>
       <xsd:complexType name="OpenCmsHtmlContent">
           <xsd:simpleContent>
               <xsd:extension base="xsd:string">
                   <xsd:attribute name="enabled" type="xsd:string"
                       use="optional" />
               </xsd:extension>
           </xsd:simpleContent>
       </xsd:complexType>
       <xsd:complexType name="OpenCmsLinkTable">
           <xsd:sequence>
               <xsd:element name="link" type="OpenCmsLink" minOccurs="0"
                   maxOccurs="unbounded" />
           </xsd:sequence>
       </xsd:complexType>
       <xsd:complexType name="OpenCmsLink">
           <xsd:sequence>
               <xsd:element name="target" type="xsd:string" />
               <xsd:element name="anchor" type="xsd:string" minOccurs="0" />
               <xsd:element name="query" type="xsd:string" minOccurs="0" />
           </xsd:sequence>
           <xsd:attribute name="name" type="xsd:string" use="required" />
           <xsd:attribute name="type" type="OpenCmsLinkType"
               use="required" />
           <xsd:attribute name="internal" type="xsd:boolean"
               use="required" />
       </xsd:complexType>
       <xsd:simpleType name="OpenCmsLinkType">
           <xsd:restriction base="xsd:string">
               <xsd:enumeration value="A" />
               <xsd:enumeration value="IMG" />
           </xsd:restriction>
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsLocale">
           <xsd:restriction base="xsd:string">
               <xsd:pattern
                   value="[a-z]{2,3}(_[A-Z]{2}(_[a-zA-Z0-9]+){0,1}){0,1}" />
           </xsd:restriction>
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsDateTime">
           <xsd:restriction base="xsd:decimal" />
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsString">
           <xsd:restriction base="xsd:string" />
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsVfsFile">
           <xsd:restriction base="xsd:string" />
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsBoolean">
           <xsd:restriction base="xsd:boolean" />
       </xsd:simpleType>
       <xsd:simpleType name="OpenCmsColor">
           <xsd:restriction base="xsd:string">
               <xsd:pattern
                   value="#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?" />
           </xsd:restriction>
       </xsd:simpleType>
   </xsd:schema>

You can edit and validate your XMLContent Schema Definition files with an external XSD editor if you save the above listing to a file and add it to your editor's XML catalog.

Editing XML Schema Definitions with Eclipse WTP

This information is about Eclipse Web Tools Platform version 1.5.2 and above.

If you have Eclipse WTP installed, it contains a great XML Schema editor with XML formatting and content assistance. You can edit the XSD files for your XMLContent there. By default, the editor does not know how to resolve the location of the opencms-xmlcontent.xsd referenced in your XSD:

<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>

It will display errors marks for the type attributes like type="OpenCmsString".

To add the Schema to the editor you must first obtain the basic OpenCms XSD file, opencms-xmlcontent.xsd, as detailed in an above section.

After that, modify the XML Catalog preferences in Eclipse. Open Window/Preferences/Web and XML/XML Catalog. Add a new User Specified Entry. For the URI select the location where you store the opencms-xmlcontent.xsd file. Select a Key Type of "Schema Location" and enter "opencms://opencms-xmlcontent.xsd" for the Key value.

Now, you should be able to edit files without seeing the error marks.

External Links

Creating XML Content Definitions

Extend Edit Options for HtmlWidget

Nice visual Tutorial for XML Content

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox