Question

I'm working in DocBook 5.0, creating a writing/editing/production environment. I validate my XML against the RNG schema version of DB5.

To make my environment easier to use, I like to break up my books into multiple files, using xinclude to pull the chapters of the book into the book file. Works great in my XSLT.

I like to use system entities to make it easier for my non-tech writers/editors to use some special characters. I set up an entities file with easy-to-use names for some common special characters (ex: &emDash; for —).

I thought I read somewhere that you cannot use both entities and xinclude in the same XML file. I just tried it, though and it validates and transforms OK. Is this ok? Is there a problem here I'm not seeing? Here's how I declare all my stuff at the top of the book file:

<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbookxi.rng" type="xml"?>
<!DOCTYPE book [
<!ENTITY % entities SYSTEM "utilities/entities/entities.ent">
%entities;
]>
<book xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" version="5.0" xml:id="book">

Thanks for any help!

Was it helpful?

Solution

You write "I thought I read somewhere that you cannot use both entities and xinclude in the same XML file."

First, the language pedant's answer:

The XInclude spec doesn't forbid the use of entities; it's not clear that it could coherently do so, because it's defined as operating at the level of the infoset, not at the level of the XML character stream. And the XML spec doesn't forbid the use of XInclude when entities are used. So neither of the defining specs for the two features you're concerned with forbid it.

Some other spec trying to define a usage profile might forbid the use of both entities and XInclude at the same time; I'm not aware of any, but that doesn't mean much. If any such profiles applied to you, however, I expect you would know about them.

Since XInclude is sometimes viewed as a way of making entities unnecessary (well, at least external entities), some XInclude enthusiasts may well regard using entities together with XInclude as being in bad taste; this will matter to you if you happen to work with any people who feel this way and care what they think, but otherwise you're free to wave merrily at them and go about your work. (I suspect that if you read something of the kind you remember, it was a statement about what the author thought was good practice or good taste; it's certainly not a statement of fact about what's legal or technically possible.)

Second, a practical answer: some processors and tool chains support the use of entities declared in the external DTD subset, some support XInclude, some support both. Check the tools you care about; if they all work with the data as you'd like to create it, you have no worries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top