Associating a RelaxNG schema with a framework by version

Having trouble installing Oxygen? Got a bug to report? Post it all here.
dcramer
Posts: 161
Joined: Sat Aug 28, 2010 1:23 am

Associating a RelaxNG schema with a framework by version

Post by dcramer »

Hi there,
I've created a customization of the DocBook 5.0 schema and, following the advice of DocBook V5.0, The Transition Guide, http://www.docbook.org/docs/howto/#cust-naming, I'm using the version attribute to distinguish instances of my documents from straight DocBook documents:

Code: Select all

<book xmlns="http://docbook.org/ns/docbook" version="5.0-extension BroadBook-2.0">
In Oxygen, I've copied the DocBook framework and modified it to use my schema instead of the DocBook schema. By moving my new Document Type above the DocBook 5 document type in the list, I can cause my documents to open using my schema, however this also causes ALL DocBook documents to open using my schema. I don't see a way to specify which version attribute a Document Type should apply to. What am I missing?

Thanks,
David
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Associating a RelaxNG schema with a framework by version

Post by george »

Dear David,

To match a framework based on an attribute value (an attribute of the root element) you need to implement a simple Java extension and set that in the Java class entry from an association rule.
Such an extension needs to implement the DocumentTypeCustomRuleMatcher interface that defines only one method:

Code: Select all


/**
* Check if the document type to which this custom rule belongs to
* should be used for the given document properties.
*
* @param systemID The system ID of the current file in an URL format with not allowed characters corrected.
* For example: "file:/C:/path/to/file/file.xml"
* @param rootNamespace The namespace of the root.
* @param rootLocalName The root local name.
* @param doctypePublicID The public id of the specified DTD if any.
* @param rootAttributes The root attributes. The attributes are DOM level 2
* and the namespaces are available for each one.
* @return <code>true</code> if the document type to which this rule belongs to
* will be used for the current file.
*/
boolean matches(
String systemID,
String rootNamespace,
String rootLocalName,
String doctypePublicID,
Attributes rootAttributes);
We have such an extension implemented for DITA that looks for the DITA architecture version attribute. The source is available in the oXygen Author SDK, look for the ro.sync.ecss.extensions.dita.topic.DITATopicCustomRuleMatcher class.

Best regards,
George
George Cristian Bina
dcramer
Posts: 161
Joined: Sat Aug 28, 2010 1:23 am

Re: Associating a RelaxNG schema with a framework by version

Post by dcramer »

Thanks George for that quick reply. I'll give it a shot.

David
dcramer
Posts: 161
Joined: Sat Aug 28, 2010 1:23 am

Re: Associating a RelaxNG schema with a framework by version

Post by dcramer »

I haven't gotten around to trying this yet, but it occurs to me that it would be useful if in the Preferences, Document Type, in the Rules tab, in addition to Namespace, Root local name, etc, there were an "XPath Expression" field which let you put in something like "/*[@version = '5.0-extension BroadBook-2.0']". If that expression evaluates to true, then the schema is used.
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: Associating a RelaxNG schema with a framework by version

Post by Radu »

Hi David,

Thanks for the suggestion.
In the meantime you can try to implement the DocumentTypeCustomRuleMatcher George mentioned and tell us if you run into any problems.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
dcramer
Posts: 161
Joined: Sat Aug 28, 2010 1:23 am

Re: Associating a RelaxNG schema with a framework by version

Post by dcramer »

Btw., I ended up implementing this as you suggested and it turned out to be pretty simple to do.

Thanks,
David
Post Reply