old-www/LDP/LDP-Author-Guide/html/tools-validate.html

1443 lines
26 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Validation</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="LDP Author Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="System Setup: Editors, Validation and
Transformations"
HREF="tools.html"><LINK
REL="PREVIOUS"
TITLE="Editing tools"
HREF="tools-edit.html"><LINK
REL="NEXT"
TITLE="Transformations"
HREF="transformations.html"></HEAD
><BODY
CLASS="section"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>LDP Author Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="tools-edit.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Appendix B. System Setup: Editors, Validation and
Transformations</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="transformations.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tools-validate"
></A
>B.3. Validation</H1
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="why-validate"
></A
>B.3.1. Why Validate Your Document</H2
><P
>&#13; The LDP uses a number of scripts to distribute your document.
These scripts submit your document to the LDP's CVS (a free
document version management system), and then they transform your document to other formats that
users then read. Your document will also be mirrored on a number
of sites worldwide (yet another set of scripts).
</P
><P
>&#13; In order for these scripts to work correctly, your document must
be both <SPAN
CLASS="QUOTE"
>"well formed"</SPAN
> and use <SPAN
CLASS="QUOTE"
>"valid
markup"</SPAN
>.
<EM
>Well formed</EM
> means your document follows the rules that XML
is expecting: it complies with XML grammar rules. <EM
>Valid
markup</EM
> means you only use elements or tags
which are <SPAN
CLASS="QUOTE"
>"valid"</SPAN
> for your
document: XML vocabulary rules are applied.
</P
><P
>&#13; If your document is not well formed or uses invalid markup, the
scripts will not be able to process it. As a result, your revised
document will not be distributed.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>The Docbook Section</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
> There is more information about how to validate
your document in the DocBook section. Check out <A
HREF="tools-validate.html"
>Section B.3</A
> for more help with validating
your document. </P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="validate-online"
></A
>B.3.2. Validation for the Faint of Heart</H2
><P
>&#13; Your life is already hard enough without having to install a full
set of tools just to see if you validate as well. You can upload your
raw XML files to a web site, then go to
<A
HREF="http://validate.sf.net"
TARGET="_top"
>http://validate.sf.net</A
>,
enter the URL to your document, then validate it.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>External entities</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; When this information was added to the Author Guide external entities
were not supported. Follow the instructions provided on the
Validate site if you have trouble.
</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="validate-local"
></A
>B.3.3. Validation for the Not So Faint Of Heart</H2
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="config-catalog"
></A
>B.3.3.1. Catalogs</H3
><P
>XML and SGML files contain most of the information you need;
however, there are sometimes entities which are specific to SGML in
general. To match these entities to their actual values you need to use a
<EM
>catalog</EM
>. The role of a catalog is to tell your
system where to find the files it is looking for. You may want to think of
a catalog as a guide book (or a map) for your tools.</P
><P
>&#13; Most distributions (Red Hat/Fedora and Debian at least) have a common location
for the main SGML catalog file, called <TT
CLASS="filename"
>/etc/sgml/catalog</TT
>.
In times past, it could also be found in <TT
CLASS="filename"
>/usr/lib/sgml/catalog</TT
>.
</P
><P
>&#13; The structure of XML catalog files is not the same as SGML catalog files.
The section on tailoring a catalog (see <A
HREF="tools-validate.html#making-catalogs"
>Section B.3.4</A
>) will give more details about what these
files actually contain.
</P
><P
>&#13; If your system cannot find the catalog file, or you are using
custom catalog files, you may need to set the
<TT
CLASS="envar"
>SGML_CATALOG_FILES</TT
> and
<TT
CLASS="envar"
>XML_CATALOG_FILES</TT
> environment variables. Using
<B
CLASS="command"
>echo <TT
CLASS="varname"
>$SGML_CATALOG_FILES</TT
></B
>,
check to see if it is currently set. If a blank line is returned,
the variable has not been set. Use the same command to see if
<TT
CLASS="envar"
>XML_CATALOG_FILES</TT
> is set as well. If the variables
are not set, use the following example to set them now.
</P
><DIV
CLASS="example"
><A
NAME="ex-catalog-files"
></A
><P
><B
>Example B-1. Setting the SGML_CATALOG_FILES and XML_CATALOG_FILES
Environmental Variables</B
></P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
><TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>export</B
> <TT
CLASS="envar"
>SGML_CATALOG_FILES="/etc/sgml/catalog"</TT
></PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>&#13; To make this change permanent, you can add the following lines to
your <TT
CLASS="filename"
>~/.bashrc</TT
> file.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="envar"
>SGML_CATALOG_FILES="/etc/sgml/catalog"</TT
>
<B
CLASS="command"
>export</B
> <TT
CLASS="envar"
>SGML_CATALOG_FILES</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; If you installed XML tools via a RedHat or Debian package, you
probably don't need to do this step. If you are using a custom XML catalog
you will definitely need to do this. There is more on custom catalogs in the next
section. To ensure my backup scripts grab this custom file, I have added
mine in a sub-directory of my home directory named <SPAN
CLASS="QUOTE"
>"docbook"</SPAN
>.
</P
><P
>&#13;<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
><TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>export</B
> <TT
CLASS="envar"
>XML_CATALOG_FILES="/home/user/docbook/db-catalog.xml"</TT
></PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>&#13;You can also change your <TT
CLASS="filename"
>.bashrc</TT
> if you want to
save these changes.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="envar"
>XML_CATALOG_FILES="/home/user/docbook/db-catalog.xml"</TT
>
<B
CLASS="command"
>export</B
> <TT
CLASS="envar"
>XML_CATALOG_FILES</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; If you are adding the changes to your
<TT
CLASS="filename"
>.bashrc</TT
> you will not see the changes
until you open a new terminal window. To make the changes immediate in the current terminal,
<SPAN
CLASS="QUOTE"
>"source"</SPAN
> the configuration file.
</P
></DIV
></DIV
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="making-catalogs"
></A
>B.3.4. Creating and modifying catalogs</H2
><P
>&#13; In the previous section I mentioned a catalog is like a guide book for
your tools. Specifically, a catalog maps the rules from the public
identifier to your system's files.
</P
><P
>&#13; At the top of every DocBook (or indeed every XML) file there is a
DOCTYPE which tells the processing tool what kind of document it is
about to be processed. At a minimum this declaration will include a public
identifier, such as <TT
CLASS="literal"
>-//OASIS//DTD DocBook
V4.2//EN</TT
>. This public identifier has a number of sections all
separated by <TT
CLASS="literal"
>//</TT
>. It contains the following
information: ISO standard if any (<TT
CLASS="literal"
>-</TT
> -- in this case
there is no ISO standard),
author (OASIS), type of document (DTD DocBook V4.2), language
(English). Your DOCTYPE may also include a URL.
</P
><P
>&#13; A public identifier is useless to a processing tool, as it needs to be
able to access the actual DTD. A URL is useless if the processing tool
is off-line. To help your processor deal with these problems you can
download all of the necessary files and then <SPAN
CLASS="QUOTE"
>"map"</SPAN
>
them for your processing tools by using a catalog.
</P
><P
>&#13; If you are using SGML processing tools (for instance Jade), you will need an
SGML catalog. If you are using XML processing tools (like XSLT), you
will need an XML catalog. Information on both is included.
</P
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="catalog-sgml"
></A
>B.3.4.1. SGML Catalogs</H3
><DIV
CLASS="example"
><A
NAME="example-catalog-sgml"
></A
><P
><B
>Example B-2. Example of an SGML catalog</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> <A
NAME="ex.catalog.comment"
><IMG
SRC="../images/callouts/1.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(1)"></A
>
-- Catalog for the Conectiva Styles --
OVERRIDE YES
<A
NAME="ex.catalog.definition"
><IMG
SRC="../images/callouts/2.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(2)"></A
>
PUBLIC "-//Conectiva SA//DTD DocBook Conectiva variant V1.0//EN"
"/home/ldp/styles/books.dtd"
DELEGATE "-//OASIS"
"/home/ldp/SGML/dtds/catalog.dtd"
<A
NAME="ex.catalog.eof"
><IMG
SRC="../images/callouts/3.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(3)"></A
>
DOCTYPE BOOK /home/ldp/SGML/dtds/docbook/db31/docbook.dtd
-- EOF --
</PRE
></TD
></TR
></TABLE
><DIV
CLASS="calloutlist"
><DL
COMPACT="COMPACT"
><DT
><A
HREF="tools-validate.html#ex.catalog.comment"
><IMG
SRC="../images/callouts/1.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(1)"></A
></DT
><DD
> Comment. Comments start with <SPAN
CLASS="QUOTE"
>"--"</SPAN
> and
follow to the end of the line. </DD
><DT
><A
HREF="tools-validate.html#ex.catalog.definition"
><IMG
SRC="../images/callouts/2.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(2)"></A
></DT
><DD
> The public type association <TT
CLASS="parameter"
><I
>"-//Conectiva SA//DTD books V1.0//EN"</I
></TT
>
with the file <TT
CLASS="filename"
>books.dtd</TT
> on the directory <TT
CLASS="filename"
>/home/ldp/styles</TT
>. </DD
><DT
><A
HREF="tools-validate.html#ex.catalog.eof"
><IMG
SRC="../images/callouts/3.gif"
HSPACE="0"
VSPACE="0"
BORDER="0"
ALT="(3)"></A
></DT
><DD
> Comment signifying the end of the file.</DD
></DL
></DIV
></DIV
><P
>As in the example above, to associate an identifier to a file just
follow the sequence shown:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Copy the identifier <EM
>PUBLIC</EM
></P
></LI
><LI
><P
>Type the identifying text </P
></LI
><LI
><P
>Indicate the path to the associated file</P
></LI
></OL
><DIV
CLASS="section"
><H4
CLASS="section"
><A
NAME="making-catalogs-commands"
></A
>B.3.4.1.1. Useful commands for catalogs</H4
><P
>The most common mappings to be used in catalogs are:</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="literal"
>PUBLIC</TT
></DT
><DD
><P
>The keyword <TT
CLASS="literal"
>PUBLIC</TT
> maps
public identifiers for identifiers on the system.</P
></DD
><DT
><TT
CLASS="literal"
>SYSTEM</TT
></DT
><DD
><P
>The <TT
CLASS="literal"
>SYSTEM</TT
> keyword maps
system identifiers for files on the system.</P
><DIV
CLASS="informalexample"
><A
NAME="AEN1931"
></A
><P
></P
><P
>&#13;SYSTEM
"http://nexus.conectiva/utilidades/publicacoes/livros.dtd"
"publicacoes/livros.dtd"</P
><P
></P
></DIV
></DD
><DT
><TT
CLASS="literal"
>SGMLDECL</TT
></DT
><DD
><P
>The keyword <TT
CLASS="literal"
>SGMLDECL</TT
> designates the
system identifier of the SGML statement that should be used.
</P
><DIV
CLASS="informalexample"
><A
NAME="AEN1939"
></A
><P
></P
><P
>&#13;SGMLDECL "publishings/books.dcl"</P
><P
></P
></DIV
></DD
><DT
><TT
CLASS="literal"
>DTDDECL</TT
></DT
><DD
><P
>Similar to the <TT
CLASS="literal"
>SGMLDECL</TT
> the
keyword <TT
CLASS="literal"
>DTDDECL</TT
> identifies the SGML statement
that should be used. <TT
CLASS="literal"
>DTDDECL</TT
> makes the
association of the statement with a public identifier to a
<SPAN
CLASS="acronym"
>DTD</SPAN
>. Unfortunately, this association isn't
supported by the open source tools available. The benefits of this
statement can be achieved somehow with multiple catalog files.
</P
><DIV
CLASS="informalexample"
><A
NAME="AEN1950"
></A
><P
></P
><P
>&#13;DTDDECL "-//Conectiva SA//DTD livros V1.0//EN" "publicacoes/livros.dcl"</P
><P
></P
></DIV
></DD
><DT
><TT
CLASS="literal"
>CATALOG</TT
></DT
><DD
><P
>The keyword <TT
CLASS="literal"
>CATALOG</TT
> allows a catalog
to be included inside another. This is a way to make use of several
different catalogs without the need to alter them.
</P
></DD
><DT
><TT
CLASS="literal"
>OVERRIDE</TT
></DT
><DD
><P
>The keyword <TT
CLASS="literal"
>OVERRIDE</TT
> informs whether an
identifier has priority over a system identifier.
The standard on most systems is that the system identifier
has priority over the public one.</P
></DD
><DT
><TT
CLASS="literal"
>DELEGATE</TT
></DT
><DD
><P
>The keyword <TT
CLASS="literal"
>DELEGATE</TT
> allows the
association of a catalog to a specific type of public identifier.
The clause <TT
CLASS="literal"
>DELEGATE</TT
> is very similar to the
<TT
CLASS="literal"
>CATALOG</TT
>, except for the fact that it doesn't do
anything until a specific pattern is specified.</P
></DD
><DT
><TT
CLASS="literal"
>DOCTYPE</TT
></DT
><DD
><P
>If a document starts with a type of document, but
has no public identifier and no system identifier the clause
<TT
CLASS="literal"
>DOCTYPE</TT
> associates this document
with a specific DTD.</P
></DD
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="catalog-xml"
></A
>B.3.4.2. XML Catalogs</H3
><P
>The following sample catalog was provided by Martin A. Brown.</P
><DIV
CLASS="example"
><A
NAME="ex-catalog-xml"
></A
><P
><B
>Example B-3. Sample XML Catalog file</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;&#60;?xml version="1.0"?&#62;
&#60;!DOCTYPE catalog PUBLIC "-//OASIS/DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"&#62;
<TT
CLASS="sgmltag"
>&#60;catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;public publicId="-//OASIS//DTD DocBook XML V4.2//EN"
uri="/home/mabrown/docbook/dtds/4.2/docbookx.dtd"/&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;uri name="http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
uri="/home/mabrown/docbook/dtds/4.2/docbookx.dtd"/&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;uri name="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"
uri="/home/mabrown/docbook/xsl/xhtml/docbook.xsl"/&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;uri name="http://docbook.sourceforge.net/release/xsl/current/xhtml/chunk.xsl"
uri="/home/mabrown/docbook/xsl/xhtml/chunk.xsl"/&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;uri name="http://docbook.sourceforge.net/release/xsl/current/xhtml/profile-chunk.xsl"
uri="/home/mabrown/docbook/xsl/xhtml/profile-chunk.xsl"/&#62;</TT
>
<TT
CLASS="sgmltag"
>&#60;/catalog&#62;</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="validatexml"
></A
>B.3.5. Validating XML</H2
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="validate-nsgmls"
></A
>B.3.5.1. nsgmls</H3
><P
>&#13; You can use <SPAN
CLASS="application"
>nsgmls</SPAN
>, which is part of the
<SPAN
CLASS="application"
>jade</SPAN
> suite (on Debian apt-get the
<SPAN
CLASS="application"
>docbook-utils</SPAN
> package, see <A
HREF="transformations.html#docbook-utils"
>Section B.4.2</A
>), to validate SGML or XML documents.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>nsgmls <TT
CLASS="parameter"
><I
>-s</I
></TT
> <TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
> If there are no issues, you'll just get your command
prompt back. The <TT
CLASS="parameter"
><I
>-s</I
></TT
> tells
<SPAN
CLASS="application"
>nsgmls</SPAN
> to show only the errors.</P
><DIV
CLASS="tip"
><P
></P
><TABLE
CLASS="tip"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Function not found</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; If you get errors about a function not being found, or
something about an ISO character not having an
authoritative source, you may
need to point <B
CLASS="command"
>nsgmls</B
> to your
<TT
CLASS="filename"
>xml.dcl</TT
> file. For Red Hat 9, it
will look like this:
<B
CLASS="command"
>nsgmls <TT
CLASS="parameter"
><I
>-s</I
></TT
>
<TT
CLASS="filename"
>/usr/share/sgml/xml.dcl</TT
>
<TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</P
></TD
></TR
></TABLE
></DIV
><P
>&#13; For more information on processing files with Jade/OpenJade please read
<A
HREF="http://www.tldp.org/HOWTO/DocBook-OpenJade-SGML-XML-HOWTO/index.html"
TARGET="_top"
>DocBook XML/SGML Processing Using OpenJade</A
>.
</P
></DIV
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="validate-onsgmls"
></A
>B.3.5.2. onsgmls</H3
><P
>&#13; This is an alternative to <SPAN
CLASS="application"
>nsgmls</SPAN
>. It ships
with the OpenJade package. This program gives more options than nsgmls
and allows you to quietly ignore a number of problems that arise while
trying to validate an XML file (as opposed to an SGML file). This also
means you don't have to type out the location of your
<TT
CLASS="filename"
>xml.dcl</TT
> file each time.
</P
><P
>&#13; I was able to simply use the following to validate a file with only
error messages that were related to my markup errors.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$ </TT
><B
CLASS="command"
>onsgmls -s <TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; According to <A
HREF="http://lists.oasis-open.org/archives/docbook-apps/200305/msg00081.html"
TARGET="_top"
>Bob
Stayton</A
> you can also turn off specific error messages. The
following example turns off XML-specific error messages.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$ </TT
><B
CLASS="command"
>onsgmls <TT
CLASS="parameter"
><I
>-s</I
></TT
> <TT
CLASS="parameter"
><I
>-wxml</I
></TT
> <TT
CLASS="parameter"
><I
>-wno-explicit-sgml-decl</I
></TT
> <TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="section"
><H3
CLASS="section"
><A
NAME="validate-xmllint"
></A
>B.3.5.3. xmllint</H3
><P
>&#13; You can also use the <SPAN
CLASS="application"
>xmllint</SPAN
> command-line tool from the <SPAN
CLASS="application"
>libxml2</SPAN
> package to validate your documents. This tool does a simple check on completeness of tags and whether all tags that are opened, are also closed again.
By default
<SPAN
CLASS="application"
>xmllint</SPAN
> will output a results tree. So if your document comes out until the last line, you know there are no heavy errors having to do with tag mismatches, opening and closing errors and the like.</P
><P
>To prevent printing the entire document to your screen, add the <TT
CLASS="parameter"
><I
>--noout</I
></TT
>
parameter.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>xmllint <TT
CLASS="parameter"
><I
>--noout</I
></TT
> <TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; If nothing is returned, your document contains no syntax errors. Else, start with the first error that was reported. Fix that one error, and run the tool again on your document. If it still returns output, again fix the first error that you see, don't botter with the rest since further errors are usually generated because of the first one.</P
><P
>&#13; If you would like to check your document for any errors which are
specific to your Document Type Definition, add
<TT
CLASS="parameter"
><I
>--valid</I
></TT
>.
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>xmllint <TT
CLASS="parameter"
><I
>--noout</I
></TT
> <TT
CLASS="parameter"
><I
>--valid</I
></TT
> <TT
CLASS="replaceable"
><I
>HOWTO.xml</I
></TT
></B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>The <B
CLASS="command"
>xmllint</B
> tool may also be used for checking errors in the XML catalogs, see the man pages for more info on how to set this behavior.</P
><P
>&#13; If you are a Mac OSX or Windows user, you may also want to check out
<SPAN
CLASS="application"
>tkxmllint</SPAN
>, a GUI version of
<SPAN
CLASS="application"
>xmllint</SPAN
>. More information is available from:
<A
HREF="http://tclxml.sourceforge.net/tkxmllint.html"
TARGET="_top"
>http://tclxml.sourceforge.net/tkxmllint.html</A
>.
</P
><DIV
CLASS="example"
><A
NAME="xmllint-example"
></A
><P
><B
>Example B-4. Debugging example using xmllint</B
></P
><P
>The example below shows how you can use <SPAN
CLASS="application"
>xmllint</SPAN
> to check your documents. I've created some errors that I made a lot, as a beginning XML writer. At first, the document doesn't come through, and errors are shown:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>bash$</TT
> <B
CLASS="command"
>xmllint <TT
CLASS="filename"
>ldp-history.xml</TT
></B
>
ldp-history.xml:22: error: Opening and ending tag mismatch: articlinfo line 6 and articleinfo
&#60;/articleinfo&#62;
^
ldp-history.xml:37: error: Opening and ending tag mismatch: listitem line 36 and orderedlist
&#60;/orderedlist&#62;
^
ldp-history.xml:39: error: Opening and ending tag mismatch: orderedlist line 34 and sect2
&#60;/sect2&#62;
^
ldp-history.xml:46: error: Opening and ending tag mismatch: sect1 line 41 and para
for many authors to contribute their part in their area of specialization.&#60;/para
^
ldp-history.xml:57: error: Opening and ending tag mismatch: para line 55 and sect1
&#60;/sect1&#62;
^
ldp-history.xml:59: error: Opening and ending tag mismatch: sect2 line 31 and article
&#60;/article&#62;
^
ldp-history.xml:61: error: Premature end of data in tag sect1 line 24
^
ldp-history.xml:61: error: Premature end of data in tag article line 5
^
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Now, as we already mentioned, don't worry about anything except the first error. The first error says there is an inconsistency between the tags on line 6 and line 22 in the file. Indeed, on line 6 we left out the <SPAN
CLASS="QUOTE"
>"e"</SPAN
> in <SPAN
CLASS="QUOTE"
>"articleinfo"</SPAN
>. Fix the error, and run <B
CLASS="command"
>xmllint</B
> again. The first complaint now is about the offending line 37, where the closing tag for list items has been forgotten. Fix the error and run the validation tool again, until all errors are gone. Most common errors include forgetting to open or close the paragraph tag, spelling errors in tags and messed up sections.</P
></DIV
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="tools-edit.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="transformations.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Editing tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="tools.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Transformations</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>