I have a docbook file me.xml
. I keep getting errors when I attempt to convert it to pdf, and I'm not sure whether the converter or my file is the problem.
Is there a quick, failsafe way that I can test whether my file is correct-formatted docbook?
First you need to know if it is a Docbook 5.x or DocBook 4.5.
Docbook 4.5 sample header:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<article>
<articleinfo>
<title/>
<author>
<firstname/>
<surname/>
<affiliation>
<orgname/>
</affiliation>
</author>
<pubdate/>
</articleinfo>
<section>
<title/>
<para/>
</section>
</article>
DocBook 5.1 sample header:
<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<info>
<title>Introduction</title>
</info>
<section>
<info>
<title>Chapter title</title>
</info>
<para>
You can see an example:
</para>
<example>
<title>main example</title>
<programlisting language="c">
</programlisting>
</example>
</section>
</chapter>
In case you use editor to create/edit your DocBook files (like XMLMind XML Editor or Oxygen Author) - it is fully editor's responsibility to make a validation and tell you if you have an error in your DocBook document. Moreover editor just don't allow you to make a wrong element inserts.
In case you just have xml
file and/or create in in any text editor - you need tools to validate it against schema in a command line.
for DocBook 4.5 you can validate against DocBook DTD using xmllint
for DocBook 5.x you can validate against using some other tools. See https://tdg.docbook.org/tdg/5.0/ch03.html
NOTE 1: if you are using DocBook 5.x and trying to validate against RelaxNG AND Schematron schemas take into account this information: https://superuser.com/questions/741957/validating-docbook-5-documents-against-both-relaxng-and-schematron
NOTE 2: don't forget that there are 2 forms of correctness of xml
files: well-formedness (correctness against XML specification) and validness (correct against specific XML vocabulary).