There are many cases where elements have a relaxed content model and can accept a large
number of child elements. For example, the DITA list item element (<li>)
accepts more than 60 child elements. Oxygen XML Author Eclipse plugin includes support to allow the
content architect to put some constraints on the possible elements or attributes, or to impose
some best practices in the way content is edited.
For an example of a specific use-case, suppose that you want to restrict DITA list item
elements (<li>) to only accept paragraph elements (<p>). In this
case, the Content Completion
Assistant should not offer any element other than a paragraph
(<p>) when a list item (<li>) is inserted into a document. It
would also be helpful if the required child element (<p>) was automatically
inserted whenever a list item (<li>) is inserted.
One method of changing the content model is to alter the element definition in the associated schema (XML Schema, DTD, RelaxNG), but this may be complicated in some cases. Fortunately, Oxygen XML Author Eclipse plugin offers a simple, alternative method of using a configuration file to customize the content completion proposals for each element.
If you extend a framework, you need to copy the content of the cc_config.xml file from the base framework and modify it (e.g. create a resources folder in your framework extension folder and place the file there). You also need to make sure that the folder that contains the cc_config.xml file in your extension (e.g. resources) is listed in the Classpath tab before the one from the base framework.
If you only want to make small changes or add extra rules in your custom content completion configuration file, you need to name it cc_config_ext.xml and all the rules inside it are merged with the base cc_config.xml file. The merging is done by taking all the rules specified in the cc_config_ext.xml file into consideration after processing the set of rules from the base cc_config.xml file.
Refresh
(F5) action to test your customizations, without
having to restart the application.<elementProposals> elements. This element allows you to customize or filter
the child elements and attributes for an element.Elements:
<elementProposals> element:path - A path within the document that matches the element
that will have its content completion proposals changed. For example,
"title" matches all the <title> elements in
the document, while "chapter/title" matches only the
<title> elements that are direct children of the
<chapter> element. You can use simplified forms of XPath in
this attribute.
The XPath expressions can accept multiple attribute conditions and inside each condition you can use AND/OR boolean operators and parentheses to override the priority.
*[@a and @b or @c and @d]
*[@a and (@b or @c) and @d]<elementProposals> element or on an ancestor element. For
example:<elementProposals xmlns:db5="http://docbook.org/ns/docbook"
path="db5:listitem" insertElements="db5:para" />@path attribute is missing, the
customization will apply to the proposals for all elements. You can
intentionally omit this attribute and use possibleElements or rejectElements to specify or restrict particular elements for
a framework.<image> and
<fig> elements because you do not want images to be
included in your output. The configuration file should look like
this:<elementProposals rejectElements="image fig" />Since the @path attribute is missing, the
specified element will be filtered out from the proposals for the entire
framework.
@path should contain the qualified name. For example, in TEI
documents, if you want to set a list of possible attributes for the
<span> element, you need to use a qualified name like
this (notice the declaration of the namespace prefix "t" and its
usage):<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oxygenxml.com/ns/ccfilter/config
http://www.oxygenxml.com/ns/ccfilter/config/ccConfigSchemaFilter.xsd"
xmlns="http://www.oxygenxml.com/ns/ccfilter/config"
xmlns:t="http://www.tei-c.org/ns/1.0">
<elementProposals path="t:span" possibleAttributes="type"/>
@path attribute is inserted into the
document, these child elements will also be inserted in the order that they are listed.
For example, insertElements="b i" will insert exactly one
<b> element, followed by an <i> element.
An empty value ("") means that no child elements should be
inserted.@path attribute. For example, "b i codeph ph" means
that the Content Completion Assistant will contain these four elements
when invoked on the element specified in the @path attribute. The
following other possible values are also supported:@insertElements attribute.<elementProposals possibleElements="b i codeph ph" />rejectElements - A space-separated list of element names that will be filtered
out from the list of proposals that are presented in the content completion list. Each
time the element specified in the @path attribute is inserted into the
document, the list of proposals in the Content Completion Assistant will
include the entries that are defined in the associated schema, minus the elements
specified in this attribute.
This setting makes the application behave as if the rejected elements were not allowed by the schema in that location. Most of the toolbar actions take the schema into account when inserting content. If the inserted content is not allowed by the schema in that particular location, the application tries to find another location within close proximity where the content is allowed.
For example, suppose you reject the insertions of images in paragraphs. If a user has the cursor inside a paragraph and uses the toolbar action that inserts an image, the image will be inserted after the current paragraph rather than at the current location.
If you want to avoid having users insert an element directly from the content completion mechanism and want them to use a toolbar action instead, it is better to use the Document Type Configuration dialog box to remove the element.
<elementProposals rejectElements="image fig imagemap foreign" />elementOnly, mixed,
or
empty.<elementProposals path="section" insertElements="title p" contentType="elementOnly"/>@merge attribute to
true on the proposal rules that might match the same element context,
all the rules will be applied.
Example: <elementProposals
path="/*[not(@xml:lang='ja')]//*"
rejectElements="japaneseTag"
merge="true"/>
<elementProposals
path="/*[@xml:lang!='he']//*"
rejectElements="hebrewTag"
merge="true"
/>Attributes:
<elementProposals> element:"title" matches all the
<title> elements in the document, while
"chapter/title" matches only the <title>
elements that are direct children of the <chapter> element. You
can use simplified forms of XPath in this attribute. For examples of such forms of XPath
expressions, see the note in XML Preferences.If this attribute is missing, the customization will apply to the proposals for all elements. You can intentionally omit this attribute and use possibleAttributes or rejectAttributes to specify or restrict attributes for an entire framework.
For example, suppose that you only want to allow a limited set of attributes in a customized framework. The configuration file should look like this:
<elementProposals possibleAttributes="
id domains href scope format type conref
props keyref class"/>
Since the @path attribute is missing, this applies to the entire
framework and only the specified attributes will be proposed.
<elementProposals path="ol/li" insertAttributes="product platform"/><elementProposals path="ol/li">
<insertAttribute name="platform" value="test"/>
</elementProposals>possibleAttributes - A space-separated list of attribute names that will be
shown in the content completion list when invoked inside an element that is specified
in the @path attribute.
<elementProposals possibleAttributes="scope format type"/>rejectAttributes - A space-separated list of attribute names that will be
filtered out from the list of proposals that are presented in the content completion
list. Each time the element specified in the @path attribute is
inserted into the document, the list of proposals in the Content Completion
Assistant will include the entries that are defined in the associated schema,
minus the attributes specified in this attribute.
<elementProposals rejectAttributes="importance platform product"/>@elementPath
and @model attributes.
Reload
(F5) action to test your customizations.elementProposals, the first one in sequence takes precedence.
Therefore, make sure you place the more specific elementProposals
(those with a longer path) first in your configuration file.@possibleElements, @rejectElements,
@possibleAttributes, and @rejectAttributes. For
example, code*, *block, con*ref,
_*.@value attribute of the
<insertAttribute> element. For
example:<elementProposals path="prolog/critdates/created">
<insertAttribute name="date" value="${date(yyyy-MM-dd)}"/>
</elementProposals>elementProposals patterns are defined,
you should avoid infinite recursions.Example 1: Automatically Insert Elements
Suppose that you want to automatically insert a paragraph element
(<p>) whenever a DITA ordered list item element
(<ol/li>) is inserted, and also to not allow any other
element besides a paragraph inside the ordered list items.
<elementProposals path="ol/li" insertElements="p"
possibleElements="_INSERTED_"/>Example 2: Insert Complex Element Structure
For a more complex example, suppose that you want to insert a complex structure
whenever a DITA <prolog> element is inserted.
<prolog>
elements: <prolog>
<author></author>
<metadata>
<keywords>
<keyword></keyword>
<keyword></keyword>
</keywords>
</metadata>
</prolog> <elementProposals path="prolog" insertElements="author metadata"/>
<elementProposals path="prolog/metadata" insertElements="keywords"/>
<elementProposals path="prolog/metadata/keywords"
insertElements="keyword, keyword"/>Example 3: Limit Possible Elements
<keywords> element to only allow the user to insert
<audience> or <keyword> elements. The
configuration file should include the
following:<elementProposals path="prolog/metadata" insertElements="keywords"
possibleElements="audience keywords"/><image> elements inside DITA list item elements
(<li>), but still propose all the other elements that are
defined in the associated schema. The configuration file should look like
this:<elementProposals path="li" rejectElements="image" />Example 1: Automatically Insert Attributes
@id attribute (with an empty
value) whenever a DITA list item element (<li>) is inserted.
The configuration file should include the
following:<elementProposals path="li" insertAttributes="id"/>Example 2: Limit Possible Attributes
<li>)
is inserted. The configuration file should look like
this:<elementProposals path="li" insertAttributes="id"
possibleAttributes="id product platform audience"/>@conref attributes inside DITA topics
(<topic> element), but still propose all the other attributes
that are defined in the associated schema. The configuration file should look like
this:<elementProposals path="topic" rejectAttributes="conref" />