<?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 2010-10-29T18:20:48.427+01:00--><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>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>