Search code examples
docbookdocbook-5

Validating Docbook 5.0, link/linkend


I am wondering why this Docbook 5.0 document is not valid:

<?xml version='1.0' encoding='utf-8'?>
<article xmlns='http://docbook.org/ns/docbook' xmlns:xlink='http://www.w3.org/1999/xlink' version='5.0'>
<section xml:id='H_0'>
<title>This is a title</title>
<para>
Blah <link linkend='H_0'>This is a link</link>blah blah blah.</para>
</section>
</article>

Here is what I get from xmlstarlet:

$ xmlstarlet val --err --xsd /usr/share/xml/docbook/schema/xsd/5.0/docbook.xsd test.xml
test.xml:3.22: Element '{http://docbook.org/ns/docbook}section', attribute '{http://www.w3.org/XML/1998/namespace}id': '' is not a valid value of the atomic type 'xs:ID'.
test.xml:6.25: Element '{http://docbook.org/ns/docbook}link', attribute 'linkend': '' is not a valid value of the atomic type 'xs:IDREF'.
test.xml - invalid

I just want internal links in the document, to the sections.

Addition: maybe this is an xmlstarlet problem, as other tools happily process the files. Anyway, I'd be glad if somebody could explain the problem.


Solution

  • Maybe it’s a bug in the version of xmlstarlet you have installed? It works for me on Debian:

    $ xmlstarlet val --err --xsd /usr/share/xml/docbook/schema/xsd/5.0/docbook.xsd -
    <?xml version='1.0' encoding='utf-8'?>
    <article xmlns='http://docbook.org/ns/docbook'
             xmlns:xlink='http://www.w3.org/1999/xlink' version='5.0'>
    <section xml:id='H_0'>
    <title>This is a title</title>
    <para>
    Blah <link linkend='H_0'>This is a link</link>blah blah blah.</para>
    </section>
    </article>
    - - valid
        ^^^^^
    

    Here’s my xmlstarlet version info:

    $ xmlstarlet --version
    1.6.1
    compiled against libxml2 2.9.4, linked with 20904
    compiled against libxslt 1.1.29, linked with 10129
    

    Incidentally, though, the DocBook document in the question isn’t actually valid—because a DocBook article element must have either a title or info child:

    $ cat > test.xml
    <?xml version='1.0' encoding='utf-8'?>
    <article xmlns='http://docbook.org/ns/docbook'
             xmlns:xlink='http://www.w3.org/1999/xlink' version='5.0'>
    <section xml:id='H_0'>
    <title>This is a title</title>
    <para>
    Blah <link linkend='H_0'>This is a link</link>blah blah blah.</para>
    </section>
    </article>
    
    $ java -jar /usr/share/java/jing.jar \
        /usr/share/xml/docbook/schema/rng/5.0/docbook.rng test.xml
    test.xml:3:23: error: element "section" not allowed yet; expected element "info",
    "subtitle", "title" or "titleabbrev"
    

    See http://tdg.docbook.org/tdg/5.0/article.html:

    article — An article.

    Synopsis

    Sequence of:

    • One of:

      • Sequence of:

        • Interleave of:

          • title
          • titleabbrev?
          • subtitle?
        • info? (db.titleforbidden.info)

      • info (db.titlereq.info)

    The lack of a ? question mark after title and info there, combined with the One of means that one or the other of title or info is required.

    I’m surprised the XSD schema doesn’t catch that. But I guess maybe it’s an indication that to make sure your DocBook documents actually are valid, you probably want to consider validating against the RelaxNG schema (/usr/share/xml/docbook/schema/rng/5.0/docbook.rng file) instead.