Search code examples
mavenpluginsdocbookoxygenxml

Is it possible to include a docbook "article" into a "book"?


got a problem with the generation from docbook to PDF.

I need to generate one PDF based on several docbook-xmls. Some of these XMLs are manually written (as the shown excerpt "book.xml" below), some of the are generated by OxygenXML (second excerpt below). The latter are XSD-schemata transferred into docbook using OxygenXML. As Oxygen does not have an option here, it always produced a docbook "article".

The file that include these articles is a docbook "book". However, inclusion produces errors: first error tells that:

element "article" from namespace "http://docbook.org/ns/docbook" 
not allowed in this context

my book.xml:

<?xml version="1.0" encoding="utf-8"?>
<book version="5.1" xml:lang="en" xmlns="http://docbook.org/ns/docbook"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink2="http://www.w3.org/1999/xlink"
  xmlns:xlink="http://www.w3.org/1999/xhtml"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:ns6="http://www.w3.org/2000/svg"
  xmlns:ns5="http://www.w3.org/1998/Math/MathML"
  xmlns:ns2="http://docbook.org/ns/transclusion"
  xmlns:ns="http://docbook.org/ns/docbook">

<title>xyz</title>

<chapter>
  <title>my xsd previously rendered by oxygen</title>
  <xi:include href="generated_schemata/my_xsd.xml"/>
</chapter>
...

and the beginning of the generated my_xsd.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbook.rng" type="xml"?>
<!--XML Schema documentation generated by <oXygen/> XML Developer.-->
<article version="5.0" xmlns="http://docbook.org/ns/docbook"
     xmlns:ns5="http://www.w3.org/1998/Math/MathML"
     xmlns:ns4="http://www.w3.org/1999/xhtml"
     xmlns:ns3="http://www.w3.org/2000/svg"
     xmlns:ns2="http://www.w3.org/1999/xlink"
     xmlns:ns="http://docbook.org/ns/docbook">
  <title>Schema documentation for ServiceCatalogue.xsd</title>

  <info>
    <pubdate>february 20, 2018</pubdate>
  </info>

  <section>
    <title>Namespace: ""</title>
...

Question: is there any way to include an docbook "article" into a "book" (or some other structure, so in the end, I get one PDF)?

Tools I am using are maven together with docbkx-plugin.


Solution

  • The problem in your code snippet is that you include (XInclude) article within chapter - not within book itself. And this is disallowed by DocBook schema (article can't be within chapter)

    I.e.:

    • book < article (or set < article) are allowed;
    • BUT this (as in your sample): book < chapter <article is NOT

    You just didn't see the full picture because of xinclude statement.

    So the workaround is (compare these two snippets):

    Yours:

    <book version="5.1" ...>
    ...
    <title>xyz</title>
    
    <chapter>
       <title>my xsd previously rendered by oxygen</title>
       <xi:include href="generated_schemata/my_xsd.xml"/>
    </chapter>
    </book>
    

    The correct one:

    <book version="5.1"...>
    ...
    <title>xyz</title>
    
    <xi:include href="generated_schemata/my_xsd.xml"/>
    
    </book>
    

    NOTE: you have different schema validation on book (5.1) and article (5.0)! Be aware about it!