<document>
<header>
<product>resin</product>
<title>JAXP - specifying XML and XSLT implementations</title>
<description>

<p>
JAXP is a standard interface which supports pluggable XML and XSL
implementations.  JAXP selects the parser based on
system properties.  You can set the properties to select
a different parser than the default one.
</p>

<p>By default, Resin will use the JDK's parsers.  Other parsers, including
Resin's own parsers can be selected with the &lt;system-property> tag.</p>

</description>
</header>

<body>
<summary/>

<s1 name="resin" title="The Resin parsers and transformers">

<deftable title="Resin XML DOM parsers">
<tr>
  <th>JAXP property</th>
  <th>Resin class
</th>
</tr>
<tr>
  <td>javax.xml.parsers.DocumentBuilderFactory</td>
  <td>com.caucho.xml.parsers.XmlDocumentBuilderFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.DocumentBuilderFactory</td>
  <td>com.caucho.xml.parsers.HtmlDocumentBuilderFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.DocumentBuilderFactory</td>
  <td>com.caucho.xml.parsers.LooseXmlDocumentBuilderFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.DocumentBuilderFactory</td>
  <td>com.caucho.xml.parsers.LooseHtmlDocumentBuilderFactory</td>
</tr>
</deftable>

<deftable title="Resin XML SAX parsers">
<tr>
  <td>javax.xml.parsers.SAXParserFactory</td>
  <td>com.caucho.xml.parsers.XmlSAXParserFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.SAXParserFactory</td>
  <td>com.caucho.xml.parsers.HtmlSAXParserFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.SAXParserFactory</td>
  <td>com.caucho.xml.parsers.LooseXmlSAXParserFactory</td>
</tr>
<tr>
  <td>javax.xml.parsers.SAXParserFactory</td>
  <td>com.caucho.xml.parsers.LooseHtmlSAXParserFactory</td>
</tr>
</deftable>

<deftable title="Resin XSLT transformer">
<tr><th>JAXP property</th><th>Resin class
</th></tr><tr><td>javax.xml.transform.TransformerFactory
    </td><td>com.caucho.xsl.Xsl
</td></tr></deftable>
<p>
Usually Resin will use its XML parsers and fast XSLT transformer.  Sometimes
placement of certain jars in the classpath causes problems.
<var>system-property</var> can be used to explicitly set the Resin XML and XSLT
implementation classes.
</p>

<example title="system-property for using Resin XML and XSLT">
&lt;!-- xml --&gt;

&lt;system-property javax.xml.parsers.DocumentBuilderFactory=
                 "com.caucho.xml.parsers.XmlDocumentBuilderFactory"/&gt;
&lt;system-property javax.xml.parsers.SAXParserFactory=
                 "com.caucho.xml.parsers.XmlSAXParserFactory"/&gt;

&lt;!--  xslt --&gt;

&lt;system-property javax.xml.transform.TransformerFactory=
                 "com.caucho.xsl.Xsl"/&gt;

</example>
</s1>

<s1 title="JDK 1.5 JAXP implementation">

<p>The Sun JDK 1.5 includes the Xerces and Xalan JAXP implementations packaged under a different name.</p>

<example title="JDK 1.5 system-property for JAXP implementations">

&lt;web-app&gt;
  &lt;!-- xml --&gt;

  &lt;system-property javax.xml.parsers.DocumentBuilderFactory=
                   "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/&gt;

  &lt;system-property javax.xml.parsers.SAXParserFactory=
                   "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/&gt;

  &lt;!--  xslt --&gt;

  &lt;system-property javax.xml.transform.TransformerFactory=
                   "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/&gt;

&lt;/web-app&gt;

</example>

</s1>

<s1 title="Using alternative XML and XSLT implementations">

<s2 title="system-property">

<p>JAXP system properties are used to specify the XML and XSLT implementations
that are used.  Resin defaults to using it's own XML parsers and fast XSLT
transformer.  Other implementations are used with the specification of the
appropriate system properties and values.</p>

<p>Examples of using <a config-tag="system-property"/> for commonly used
alternative XML parsers and XSLT transformers are in separate sections 
below.  The system property configuration tags can be placed at the 
<a config-tag="web-app"/> or the <a config-tag="server"/> level.</p>

<example title="system-property to specify xml parser for web-app">

&lt;web-app&gt;
  &lt;!-- xml --&gt;

  &lt;system-property javax.xml.parsers.DocumentBuilderFactory=
               "..."/&gt;
  &lt;system-property javax.xml.parsers.SAXParserFactory=
               "..."/&gt;

  &lt;!--  xslt --&gt;

  &lt;system-property javax.xml.transform.TransformerFactory=
               "..."/&gt;
&lt;/web-app&gt;

</example>

<example title="system-property to specify xml parser for server">

&lt;server&gt;
  &lt;!-- xml --&gt;

  &lt;system-property javax.xml.parsers.DocumentBuilderFactory=
               "..."/&gt;
  &lt;system-property javax.xml.parsers.SAXParserFactory=
               "..."/&gt;

  &lt;!-- xslt --&gt;

  &lt;system-property javax.xml.transform.TransformerFactory=
               "..."/&gt;
&lt;/server&gt;

</example>

</s2>

<s2 title="jar file placement">

<p>Setting system properties for alternative libraries requires that the
implementation classes, usually in a .jar file, are available in the classpath.

</p><p>
The implementation classes are available for a single web application when the
jar file(s) are placed in <code>WEB-INF/lib</code>.  Since other web-apps do not see
these libraries,  this allows you to isolate a particular version of a
particular implementation for use by the web-app.  It is not uncommon for a new
version of these jar files to introduce problems with existing code.  </p>

<p>
If the <code>system-property</code> is being set at the server level, then the jar
files containing the implementation classes need to be placed in
<code>$RESIN_HOME/lib</code>.   This is also a convenient location for placement if
you want to avoid putting the libraries in <code>WEB-INF/lib</code> for every
web application.  Any jars placed in <code>$RESIN_HOME/lib</code> are
avaialable for all web applications.
</p>

</s2>
</s1>

<s1 name="xerces" title="Using Xalan and Xerces">

<example title="system-property for using Xalan and Xerces">
&lt;!-- xml --&gt;

&lt;system-property javax.xml.parsers.DocumentBuilderFactory=
             "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/&gt;
&lt;system-property javax.xml.parsers.SAXParserFactory=
             "org.apache.xerces.jaxp.SAXParserFactoryImpl"/&gt;

&lt;!--  xslt --&gt;

&lt;system-property javax.xml.transform.TransformerFactory=
             "org.apache.xalan.processor.TransformerFactoryImpl"/&gt;

</example>

<p>
Cocoon users may need the following:
</p>

<example title="system-property for cocoon users using Xalan and Xerces">
&lt;system-property org.xml.sax.driver=
             "org.apache.xerces.parsers.SAXParser"/&gt;
</example>

<p>
Put your xerces and xalan jar files in <code>WEB-INF/lib</code>, or to have them
available to all of your applications put them in <code>$RESIN_HOME/lib</code>.
</p>

</s1>

<s1 name="crimson" title="Using Crimson">

<p>Crimson is the xml parser that is included with JDK 1.4.</p>

<example title="system-property for using Crimson">

&lt;!-- xml --&gt;

&lt;system-property javax.xml.parsers.DocumentBuilderFactory=
             "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl"/&gt;
&lt;system-property javax.xml.parsers.SAXParserFactory=
             "org.apache.crimson.jaxp.SAXParserFactoryImpl"/&gt;

</example>
</s1>

</body>
</document>
