XSD constraint modules consist of one or two XSD documents that redefine the content model or attribute list to be constrained. Whether the constraint requires one document two depends on the details of the constraint being applied and the group being constrained. This particular constraint requires an intermediate XSD file in order to work around limitations in the way the redefine feature works. Essentially, we have to clear the content of <p>
and then extend it, which requires two levels of redefinition.
Eventually you will move this shell schema to a different directory, but for now putting all the pieces in one directory makes setup and testing easier. Once everything is working in this location you can reorganize the files and know when you've got everything hooked up right again.
<?xml version="1.0" encoding="UTF-8"?> <topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="topic-with-highlight-constraint.xsd" id="topicid"> <title>Test of Simple Paragraph Restriction</title> <body> <p><b>b</b>, <i>i</i>, <u>u</u>. Not allowed <keyword>keyword</keyword>.</p> <p></p> </body> </topic>
<p>
element, so the first task is to find where p's content model is defined in the XSD files that make up the base <topic>
vocabulary module. One way to do this is to search for 'name="p.content"' across all the standard XSD modules (for example, using OxygenXML's "Find in files" feature or using Search in Windows Explorer"). You should find the group definition for "p.content" in commonElementMod.xsd
. It looks like this:<xs:group name="p.content"> <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:group ref="para.cnt" minOccurs="0"/> </xs:choice> </xs:sequence> </xs:group>
highlightOnlyPConstraintsInt.xsd
and give it this content:<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:annotation> <xs:documentation>Intermediate level of redefine to work around XSD redefine limitations </xs:documentation> </xs:annotation> <xs:redefine schemaLocation="urn:oasis:names:tc:dita:xsd:commonElementMod.xsd:1.2"> <!-- constrain content of <p> element --> <xs:group name="p.content"> <xs:choice> <!-- "clear" p.content so we can then override it again in the next level of redefine. --> </xs:choice> </xs:group> </xs:redefine> <xs:group name="p-highlight-only.content"> <xs:choice> <xs:sequence maxOccurs="unbounded"> <xs:group ref="b" minOccurs="0"/> <xs:group ref="i" minOccurs="0"/> <xs:group ref="u" minOccurs="0"/> </xs:sequence> </xs:choice> </xs:group> </xs:schema>
This schema document redefines <p>
as declared in commonElementMod.xsd
to be an empty group. This document also defines a new group containing the new content model we want for <p>
.
highlightOnlyPConstraintsInt.xsd
and defines "p.content" to use the "p-highlight-only.content" content group also defined in highlightOnlyPConstraintsInt.xsd
:<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:redefine schemaLocation="highlightOnlyPConstraintsInt.xsd"> <!-- constrain content of <p> element --> <xs:group name="p.content"> <xs:choice> <xs:group ref="p-highlight-only.content"/> </xs:choice> </xs:group> </xs:redefine> </xs:schema>
... <xs:include schemaLocation="urn:oasis:names:tc:dita:xsd:topicMod.xsd:1.2"/> <xs:include schemaLocation="highlightOnlyTopicConstraints.xsd" /> <xs:group name="info-types"> <xs:sequence/> </xs:group> ...
This includes the constraint module in the XSD document type shell.
<!-- ================= MODULE INLCUDE DEFINITION ================== --> <!-- <xs:include schemaLocation="urn:oasis:names:tc:dita:xsd:commonElementMod.xsd:1.2"/> -->
<b>
, <i>
, or <u>
in it (e.g., <keyword>
).... <xs:attributeGroup name="domains-att"> <xs:attribute name="domains" type="xs:string" default="(topic highlightOnlyP-c) (topic ui-d) (topic hi-d) (topic sw-d) (topic pr-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d)"/> </xs:attributeGroup> ...
<b>
, <i>
, and <u>
within <p>
. At this point you could package the constraint module and the shell document type into Toolkit plugins.