<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="sourcedocs" page="ptree" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: The PTree File Format</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: The PTree File Format"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>The PTree File Format</h1>
      <p>Saxon-PE and Saxon-EE support a file format called the PTree (persistent tree). This is a binary representation of an
 XML document. The PTree file is generally about the same size as the original document (perhaps 10% smaller),
 but it typically loads in about half the time. Storing a document as a PTree can therefore give a useful
 performance improvement when the same source document is used repeatedly as the input to many queries
 or transformations. Another benefit of the PTree is that it retains any type information that is present, 
 which means that the document does not need to be validated against its schema each time it is loaded. (The 
 schema, however, must be loaded whenever the document is loaded.)</p>
      <p>Two commands are available for converting XML documents into PTree files and vice versa. To create
 a PTree, use:</p>
      <p class="command">java  com.saxonica.ptree.PTreeWriter source.xml result.ptree</p>
      <p>The option <code>-strip</code> causes all whitespace-only text nodes to be stripped in the process,
 which will often give a useful saving in space and therefore in loading time.</p>
      <p>To convert a PTree back to an XML document, use:</p>
      <p class="command">java  com.saxonica.ptree.PTreeReader source.ptree result.xml</p>
      <p>It is possible to apply a query or transformation directly to a PTree by specifying the <code>-p</code>
option on the command line for <code>com.saxonica.Transform</code> or <code>com.saxonica.Query</code>.
This option actually causes a different URIResolver, the <a class="bodylink" href="../javadoc/com/saxonica/ptree/PTreeURIResolver.html"><code>PTreeURIResolver</code></a>, to be used in 
place of the standard URIResolver. The <code>PTreeURIResolver</code> recognizes any URI ending in the
extension <code>.ptree</code> as an identifier for a file in PTree format. This extends to files loaded using the
<code>doc()</code> or <code>document()</code> functions: if the file extension is <code>.ptree</code>, the
file will be assumed to be in PTree format.</p>
      <p>The result of a query or transformation can be serialized as a PTree file by specifying <code>saxon:ptree</code>
as the output method, where the namespace prefix <code>saxon</code> represents the URI
<code>http://saxon.sf.net/</code>.</p>
      <p>The PTree format is designed to allow future Saxon releases to read files created using older releases. The
converse may not always be true: it might sometimes be impossible for release N to read a PTree file created
using release N+1.</p>
      <p>In releases up to and including Saxon 9.3, the PTree files were always at version 0. Saxon 9.4 introduces a new
        version, version 1. The new version differs in retaining DTD-derived attribute types (ID, IDREF, IDREFS). The
        <a class="bodylink" href="../javadoc/com/saxonica/ptree/PTreeReader.html"><code>PTreeReader</code></a> in Saxon 9.4 (onwards) will read both versions. 
        The <a class="bodylink" href="../javadoc/com/saxonica/ptree/PTreeWriter.html"><code>PTreeWriter</code></a> in Saxon 9.4 writes version 1 output by default
        (which cannot be read by earlier releases), but it can still write original version 0 output
        if requested. If called from the command line, use the option <code>-version:1</code>.</p>
      <p>The PTree format does not retain the base URI of the original file: when a PTree is loaded, the base URI is taken
as the URI of that file, not the original XML file. The PTree is a serialization of the XPath data model, so information
that isn't present in the data model will not be present in the PTree: for example, it will have no DTD and no
entity references or CDATA sections.</p>
      <p>References to unparsed entities are not currently retained in a PTree.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="validation.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>