<commit_before><?xml version="1.0" encoding="UTF-8"?>
<book>
    <bookinfo>
        <graphic fileref="logo.jpg"/>
        <productname>Open Source Native XML Database</productname>
        <title>XML Validation</title>
        <author>
            <firstname>Dannes</firstname>
            <surname>Wessels</surname>
            <affiliation>
                <address format="linespecific">
                    <email>dizzzz at exist-db.org</email>
                </address>
            </affiliation>
        </author>
    </bookinfo>

    <ci:include xmlns:ci="http://apache.org/cocoon/include/1.0" src="sidebar.xml"/>

    <chapter>
        <title>XML Validation</title>
        <section id="sect1">
            <title>Introduction</title>
            <para>The database supports implicit and explicit validation of XML documents. Implicit
                validation can be executed automagically when documents are being inserted into the
                database, explicit validation can be performed using xquery extension
            functions.</para>
        </section>
        <section id="sect2">
            <title>Implicit validation</title>
            <para>To enable this feature the eXist-db configuration must be changed by editing the
                file <filename>conf.xml</filename>. The following items must be configured:<itemizedlist>
                    <listitem>
                        <para>Validation mode</para>
                    </listitem>
                    <listitem>
                        <para>Catalog Entity Resolver</para>
                    </listitem>
                </itemizedlist>
            </para>
            <para>
                <example>
                    <title>Default configuration</title>
                    <programlisting format="linespecific"><![CDATA[
    <validation mode="auto">
        <entity-resolver>
            <catalog uri="${WEBAPP_HOME}/WEB-INF/catalog.xml" />
        </entity-resolver>
    </validation>]]></programlisting>
                </example> Catalog documentss can also be stored inside the database, which is much
                more flexible compared the previous example. Please note the three forward slashes
                /// here... <example>
                    <title>Default configuration</title>
                    <programlisting format="linespecific"><![CDATA[
    <validation mode="auto">
        <entity-resolver>
            <catalog uri="xmldb:exist:///db/grammar/catalog.xml" />
            <catalog uri="${WEBAPP_HOME}/WEB-INF/catalog.xml" />
        </entity-resolver>
    </validation>]]></programlisting>
                </example>
            </para>

            <section>
                <title>Validation mode</title>
                <para>With the parameter <emphasis>mode</emphasis> it is possible to switch on/off
                    the validation capabilities of the (Xerces) XML parser. The possible values are:</para>
                <section>
                    <title>yes</title>
                    <para>Switch on validation. All XML documents will be validated. When the
                        grammar (XML schema, DTD) documents cannot be resolved, the document is
                        rejected.</para>
                </section>
                <section>
                    <title>no</title>
                    <para>Switch off validation. All well-formed XML documents will be
                    accepted.</para>
                </section>
                <section>
                    <title>auto (default)</title>
                    <para>Validation of an XML document will be performed based on the contents of
                        the document. When a document contains a reference to a grammar
                            (<emphasis>XML schema</emphasis> or <emphasis>DTD</emphasis>) document,
                        the XML parser tries to resolve this grammar and the XML document will be
                        validated against this grammar, just like <emphasis>mode="yes"</emphasis> is
                        configured. If the grammar cannot be resolved, the XML document will be
                        rejected. When the XML document does not contain a reference to a grammar,
                        it will be parsed like <emphasis>mode="no"</emphasis> is configured.</para>
                </section>
            </section>


            <section>
                <title>Catalog Entity Resolver</title>
                <para>All grammar (XML schema, DTD) files that must be part of the implicit
                    validation process must be registered to the database using <ulink
                        url="http://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html"
                        >OASIS catalog</ulink> files. These catalog files can be stored on disk and
                    in the database.</para>
                <para>In the upper example the ${WEBAPP_HOME} is substituted by a
                    <emphasis>file://</emphasis> URL pointing to the 'webapp'-directory of eXist
                    (e.g. '$EXIST_HOME/webapp/') or the equivalent directory of a deployed WAR file
                    when eXist is deployed in a servlet container (e.g.
                    '${CATALINA_HOME}/webapps/exist/')</para>
                <para>A catalog which is stored in the database can be addressed by an URL like
                    'xmldb:exist:///db/mycollection/catalog.xml' (note the 3 slashes) or the shorter
                    equivalent '/db/mycollection/catalog.xml'.</para>
                <para>
                    <example>
                        <title>Default OASIS catalog file</title>
                        <programlisting format="linespecific"><![CDATA[
    <?xml version="1.0" encoding="UTF-8"?>
    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
        <public publicId="-//PLAY//EN" uri="entities/play.dtd"/>
        <system systemId="play.dtd" uri="entities/play.dtd"/>
        <system systemId="mondial.dtd" uri="entities/mondial.dtd"/>    
        
        <uri name="http://exist-db.org/samples/shakespeare" uri="entities/play.xsd"/>
        
        <uri name="http://www.w3.org/XML/1998/namespace" uri="entities/xml.xsd"/>
    	<uri name="http://www.w3.org/2001/XMLSchema" uri="entities/XMLSchema.xsd"/>
    
        <uri name="urn:oasis:names:tc:entity:xmlns:xml:catalog" uri="entities/catalog.xsd" />
    </catalog>]]></programlisting>
                    </example>
                </para>
                <para>It is possible to configure any number of catalog entries in the
                    entity-resolver section of conf.xml . The relative "uri="s are resolved
                    relative to the location of the catalog document</para>
            </section>

            <section>
                <title>Collection validation configuration</title>
                <para>The validation mode for each individal collection can be configured using
                        <emphasis>collection.xconf</emphasis> documents, in the same way these are
                    used for configuring <a href="indexing.xml">indexes</a>. These documents need to
                    be stored in '/db/system/config/db/....'.</para>
                <example>
                    <title>collection.xconf</title>
                    <programlisting format="linespecific"><![CDATA[
<?xml version='1.0'?>
<collection xmlns="http://exist-db.org/collection-config/1.0">
    <validation mode="yes"/>
</collection>]]></programlisting>
                </example>
            </section><commit_msg>[documentation] Added some notes about stored catalog documents.<commit_after><?xml version="1.0" encoding="UTF-8"?>
<book>
    <bookinfo>
        <graphic fileref="logo.jpg"/>
        <productname>Open Source Native XML Database</productname>
        <title>XML Validation</title>
        <author>
            <firstname>Dannes</firstname>
            <surname>Wessels</surname>
            <affiliation>
                <address format="linespecific">
                    <email>dizzzz at exist-db.org</email>
                </address>
            </affiliation>
        </author>
    </bookinfo>

    <ci:include xmlns:ci="http://apache.org/cocoon/include/1.0" src="sidebar.xml"/>

    <chapter>
        <title>XML Validation</title>
        <section id="sect1">
            <title>Introduction</title>
            <para>The database supports implicit and explicit validation of XML documents. Implicit
                validation can be executed automagically when documents are being inserted into the
                database, explicit validation can be performed using xquery extension
            functions.</para>
        </section>
        <section id="sect2">
            <title>Implicit validation</title>
            <para>To enable this feature the eXist-db configuration must be changed by editing the
                file <filename>conf.xml</filename>. The following items must be configured:<itemizedlist>
                    <listitem>
                        <para>Validation mode</para>
                    </listitem>
                    <listitem>
                        <para>Catalog Entity Resolver</para>
                    </listitem>
                </itemizedlist>
            </para>
            <para>
                <example>
                    <title>Default configuration</title>
                    <programlisting format="linespecific"><![CDATA[
    <validation mode="auto">
        <entity-resolver>
            <catalog uri="${WEBAPP_HOME}/WEB-INF/catalog.xml" />
        </entity-resolver>
    </validation>]]></programlisting>
                </example> Catalog documents can also be stored inside the database, which is much
                more flexible compared the previous example. Please note the three forward slashes
                /// here... <example>
                    <title>Catalog stored in database</title>
                    <programlisting format="linespecific"><![CDATA[
    <validation mode="auto">
        <entity-resolver>
            <catalog uri="xmldb:exist:///db/grammar/catalog.xml" />
            <catalog uri="${WEBAPP_HOME}/WEB-INF/catalog.xml" />
        </entity-resolver>
    </validation>]]></programlisting>
                </example>
            </para>

            <section>
                <title>Validation mode</title>
                <para>With the parameter <emphasis>mode</emphasis> it is possible to switch on/off
                    the validation capabilities of the (Xerces) XML parser. The possible values are:</para>
                <section>
                    <title>yes</title>
                    <para>Switch on validation. All XML documents will be validated. When the
                        grammar (XML schema, DTD) documents cannot be resolved, the document is
                        rejected.</para>
                </section>
                <section>
                    <title>no</title>
                    <para>Switch off validation. All well-formed XML documents will be
                    accepted.</para>
                </section>
                <section>
                    <title>auto (default)</title>
                    <para>Validation of an XML document will be performed based on the contents of
                        the document. When a document contains a reference to a grammar
                            (<emphasis>XML schema</emphasis> or <emphasis>DTD</emphasis>) document,
                        the XML parser tries to resolve this grammar and the XML document will be
                        validated against this grammar, just like <emphasis>mode="yes"</emphasis> is
                        configured. If the grammar cannot be resolved, the XML document will be
                        rejected. When the XML document does not contain a reference to a grammar,
                        it will be parsed like <emphasis>mode="no"</emphasis> is configured.</para>
                </section>
            </section>


            <section>
                <title>Catalog Entity Resolver</title>
                <para>All grammar (XML schema, DTD) files that must be part of the implicit
                    validation process must be registered to the database using <ulink
                        url="http://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html"
                        >OASIS catalog</ulink> files. These catalog files can be stored on disk and
                    in the database.</para>
                <para>In the upper example the ${WEBAPP_HOME} is substituted by a
                    <emphasis>file://</emphasis> URL pointing to the 'webapp'-directory of eXist
                    (e.g. '$EXIST_HOME/webapp/') or the equivalent directory of a deployed WAR file
                    when eXist is deployed in a servlet container (e.g.
                    '${CATALINA_HOME}/webapps/exist/')</para>
                <para>A catalog which is stored in the database can be addressed by an URL like
                    'xmldb:exist:///db/mycollection/catalog.xml' (note the 3 slashes) or the shorter
                    equivalent '/db/mycollection/catalog.xml'.</para>
                <para>
                    <example>
                        <title>Default OASIS catalog file</title>
                        <programlisting format="linespecific"><![CDATA[
    <?xml version="1.0" encoding="UTF-8"?>
    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
        <public publicId="-//PLAY//EN" uri="entities/play.dtd"/>
        <system systemId="play.dtd" uri="entities/play.dtd"/>
        <system systemId="mondial.dtd" uri="entities/mondial.dtd"/>    
        
        <uri name="http://exist-db.org/samples/shakespeare" uri="entities/play.xsd"/>
        
        <uri name="http://www.w3.org/XML/1998/namespace" uri="entities/xml.xsd"/>
    	<uri name="http://www.w3.org/2001/XMLSchema" uri="entities/XMLSchema.xsd"/>
    
        <uri name="urn:oasis:names:tc:entity:xmlns:xml:catalog" uri="entities/catalog.xsd" />
    </catalog>]]></programlisting>
                    </example>
                </para>
                <para>It is possible to configure any number of catalog entries in the
                    entity-resolver section of conf.xml . The relative "uri="s are resolved
                    relative to the location of the catalog document.</para>
            </section>

            <section>
                <title>Collection validation configuration</title>
                <para>The validation mode for each individal collection can be configured using
                        <emphasis>collection.xconf</emphasis> documents, in the same way these are
                    used for configuring <a href="indexing.xml">indexes</a>. These documents need to
                    be stored in '/db/system/config/db/....'.</para>
                <example>
                    <title>collection.xconf</title>
                    <programlisting format="linespecific"><![CDATA[
<?xml version='1.0'?>
<collection xmlns="http://exist-db.org/collection-config/1.0">
    <validation mode="yes"/>
</collection>]]></programlisting>
                </example>
            </section>
{'fraction_non_alphanumeric': 0.10604079497907949, 'fraction_numerical': 0.003922594142259414, 'mean_word_length': 1.7218861209964413, 'pattern_counts': {'":': 0, '<': 333, '<?xml version=': 6, '>': 333, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 46}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5769636', 'n_tokens_mistral': 3916, 'n_tokens_neox': 3615, 'n_words': 1086}