<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Pxp_codewriter.html"> <link rel="next" href="Pxp_yacc.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of class methods" rel=Appendix href="index_methods.html"> <link title="Index of classes" rel=Appendix href="index_classes.html"> <link title="Index of class types" rel=Appendix href="index_class_types.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Pxp_types" rel="Chapter" href="Pxp_types.html"> <link title="Pxp_document" rel="Chapter" href="Pxp_document.html"> <link title="Pxp_dtd" rel="Chapter" href="Pxp_dtd.html"> <link title="Pxp_tree_parser" rel="Chapter" href="Pxp_tree_parser.html"> <link title="Pxp_core_types" rel="Chapter" href="Pxp_core_types.html"> <link title="Pxp_ev_parser" rel="Chapter" href="Pxp_ev_parser.html"> <link title="Pxp_event" rel="Chapter" href="Pxp_event.html"> <link title="Pxp_dtd_parser" rel="Chapter" href="Pxp_dtd_parser.html"> <link title="Pxp_codewriter" rel="Chapter" href="Pxp_codewriter.html"> <link title="Pxp_marshal" rel="Chapter" href="Pxp_marshal.html"> <link title="Pxp_yacc" rel="Chapter" href="Pxp_yacc.html"> <link title="Pxp_reader" rel="Chapter" href="Pxp_reader.html"> <link title="Intro_trees" rel="Chapter" href="Intro_trees.html"> <link title="Intro_extensions" rel="Chapter" href="Intro_extensions.html"> <link title="Intro_namespaces" rel="Chapter" href="Intro_namespaces.html"> <link title="Intro_events" rel="Chapter" href="Intro_events.html"> <link title="Intro_resolution" rel="Chapter" href="Intro_resolution.html"> <link title="Intro_getting_started" rel="Chapter" href="Intro_getting_started.html"> <link title="Intro_advanced" rel="Chapter" href="Intro_advanced.html"> <link title="Intro_preprocessor" rel="Chapter" href="Intro_preprocessor.html"> <link title="Example_readme" rel="Chapter" href="Example_readme.html"><link title="Marshalling" rel="Section" href="#2_Marshalling"> <link title="Unmarshalling" rel="Section" href="#2_Unmarshalling"> <link title="Relocation" rel="Section" href="#2_Relocation"> <title>PXP Reference : Pxp_marshal</title> </head> <body> <div class="navbar"><a href="Pxp_codewriter.html">Previous</a> <a href="index.html">Up</a> <a href="Pxp_yacc.html">Next</a> </div> <center><h1>Module <a href="type_Pxp_marshal.html">Pxp_marshal</a></h1></center> <br> <pre><span class="keyword">module</span> Pxp_marshal: <code class="code"><span class="keyword">sig</span></code> <a href="Pxp_marshal.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Marshalling of XML trees<br> <hr width="100%"> <br> This module allows fast marshalling of subtrees. The standard O'Caml marshalling implementation does not work because O'Caml does not support marshalling of objects. Because of this, the objects must be transformed into a representation for which no marshalling restriction applies. <p> The subtree is converted into a sequence of <code class="code">reconstruction_cmd</code> values which can be marshaled using the standard implementation. <p> While the tree is written or read it is possible to change the character encoding. Furthermore, the namespace prefixes can be changed to other conventions.<br> <pre><span class="keyword">type</span> <a name="TYPEreconstruction_cmd"></a><code class="type"></code>reconstruction_cmd </pre> <div class="info"> A tree is translated into a sequence of <code class="code">reconstrucion_cmd</code> tokens. These tokens can be subsequently translated into byte strings using the standard <code class="code"><span class="constructor">Marshal</span></code> module.<br> </div> <br> <a name="2_Marshalling"></a> <h2>Marshalling</h2><br> <pre><span class="keyword">val</span> <a name="VALsubtree_to_cmd_sequence"></a>subtree_to_cmd_sequence : <code class="type">?omit_positions:bool -><br> ?enc:Netconversion.encoding -><br> (<a href="Pxp_marshal.html#TYPEreconstruction_cmd">reconstruction_cmd</a> -> unit) -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.node.html">Pxp_document.node</a> -><br> unit</code></pre><div class="info"> <code class="code">subtree_to_cmd_sequence f n</code>: The passed node <code class="code">n</code> is the root of the subtree to be marshaled. The function <code class="code">f</code> is called several times with the sequence of <code class="code">reconstruction_cmd</code> values that contain the contents of the subtree. <p> If the subtree has a namespace manager, the information contained in this object is marshaled, too. The namespace scope objects are also represented in the command sequence. <p> <code class="code">omit_positions</code>: If true, the position strings of the nodes which contain line numbers are omitted. Default: false <p> <code class="code">enc</code>: if passed, the character encoding is changed to this type. If omitted, the written sequence is encoded in the same manner as the node tree.<br> </div> <pre><span class="keyword">val</span> <a name="VALsubtree_to_channel"></a>subtree_to_channel : <code class="type">?omit_positions:bool -><br> ?enc:Netconversion.encoding -><br> Pervasives.out_channel -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.node.html">Pxp_document.node</a> -><br> unit</code></pre><div class="info"> <code class="code">subtree_to_channel ch n</code>: The node <code class="code">n</code> is the root of the subtree to be marshaled; the external representation is written to <code class="code">ch</code> (which must have been opened in binary mode). (Info about namespaces: see subtree_to_cmd_sequence.) <p> <code class="code">omit_positions</code>: If true, the position strings of the nodes which contain line numbers are omitted. Default: false <p> <code class="code">enc</code>: if passed, the character encoding is changed to this type. If omitted, the written sequence is encoded in the same manner as the node tree.<br> </div> <pre><span class="keyword">val</span> <a name="VALdocument_to_cmd_sequence"></a>document_to_cmd_sequence : <code class="type">?omit_positions:bool -><br> ?enc:Netconversion.encoding -><br> (<a href="Pxp_marshal.html#TYPEreconstruction_cmd">reconstruction_cmd</a> -> unit) -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.document.html">Pxp_document.document</a> -><br> unit</code></pre><div class="info"> The same for documents<br> </div> <pre><span class="keyword">val</span> <a name="VALdocument_to_channel"></a>document_to_channel : <code class="type">?omit_positions:bool -><br> ?enc:Netconversion.encoding -><br> Pervasives.out_channel -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.document.html">Pxp_document.document</a> -><br> unit</code></pre><div class="info"> The same for documents.<br> </div> <br> <a name="2_Unmarshalling"></a> <h2>Unmarshalling</h2><br> <pre><span class="keyword">val</span> <a name="VALsubtree_from_cmd_sequence"></a>subtree_from_cmd_sequence : <code class="type">(unit -> <a href="Pxp_marshal.html#TYPEreconstruction_cmd">reconstruction_cmd</a>) -><br> <a href="Pxp_dtd.dtd.html">Pxp_dtd.dtd</a> -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'a <a href="Pxp_document.node.html">Pxp_document.node</a></code></pre><div class="info"> Reconstructs the subtree from a sequence of <code class="code">reconstruction_cmd</code> values. The passed function is called repeatedly to get the stream of <code class="code">reconstruction_cmd</code>. <p> If the DTD contains a namespace_manager: You must pass a namespace_manager to enable the namespace code. Note that the normprefixes found in the input stream are remapped to unique normprefixes, if this is necessary. This means that the namespace_manager should be filled with (normprefix, uri) pairs if you want to ensure that certain normprefixes are used. If you pass an empty namespace_manager, it is guaranteed that such remapping is not necessary, so the normprefixes are the same as in the original document. The namespace scope objects are retained, and thus the display prefixes are the same as in the original tree. <p> The character encoding of the node tree is set to the encoding of the DTD. If necessary, the read strings are recoded.<br> </div> <pre><span class="keyword">val</span> <a name="VALsubtree_from_channel"></a>subtree_from_channel : <code class="type">Pervasives.in_channel -><br> <a href="Pxp_dtd.dtd.html">Pxp_dtd.dtd</a> -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'a <a href="Pxp_document.node.html">Pxp_document.node</a></code></pre><div class="info"> Reconstructs the subtree from an <code class="code">in_channel</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALdocument_from_cmd_sequence"></a>document_from_cmd_sequence : <code class="type">(unit -> <a href="Pxp_marshal.html#TYPEreconstruction_cmd">reconstruction_cmd</a>) -><br> <a href="Pxp_yacc.html#TYPEconfig">Pxp_yacc.config</a> -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'a <a href="Pxp_document.document.html">Pxp_document.document</a></code></pre><div class="info"> The same for documents<br> </div> <pre><span class="keyword">val</span> <a name="VALdocument_from_channel"></a>document_from_channel : <code class="type">Pervasives.in_channel -><br> <a href="Pxp_yacc.html#TYPEconfig">Pxp_yacc.config</a> -><br> ('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'a <a href="Pxp_document.document.html">Pxp_document.document</a></code></pre><div class="info"> The same for documents. <p> The character encoding of the node tree is set to the encoding of the configuration. If necessary, the read strings are recoded.<br> </div> <br> <a name="2_Relocation"></a> <h2>Relocation</h2><br> <br> The term "relocation" is here used for creating a copy of a tree or document by printing and reparsing. This can be useful, because other model specifications can be used while building the copy (i.e. a different set of classes is instantiated for the same elements). <p> The following functions avoid expensive reparsing, but take the shortcut of decomposing the original tree into <code class="code">reconstruction_cmd</code> sequences and recombining them afterwards to create the copy.<br> <pre><span class="keyword">val</span> <a name="VALrelocate_subtree"></a>relocate_subtree : <code class="type">('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.node.html">Pxp_document.node</a> -><br> <a href="Pxp_dtd.dtd.html">Pxp_dtd.dtd</a> -><br> ('b <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'b) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'b <a href="Pxp_document.node.html">Pxp_document.node</a></code></pre><div class="info"> Creates a copy of the passed subtree by marshalling the tree, and restoring the marshaled tree. The new tree will have the passed DTD and the passed spec, i.e. <b>this function can change the DTD and the spec while copying a tree</b>. Note that you can also change the type of the extensions. <p> This function is optimized, and works block by block in order to avoid large temporary values. <p> See also <code class="code">relocate_documents</code> for known problems of relocation.<br> </div> <pre><span class="keyword">val</span> <a name="VALrelocate_document"></a>relocate_document : <code class="type">('a <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'a) <a href="Pxp_document.document.html">Pxp_document.document</a> -><br> <a href="Pxp_yacc.html#TYPEconfig">Pxp_yacc.config</a> -><br> ('b <a href="Pxp_document.node.html">Pxp_document.node</a> #<a href="Pxp_document.extension.html">Pxp_document.extension</a> as 'b) <a href="Pxp_document.html#TYPEspec">Pxp_document.spec</a> -><br> 'b <a href="Pxp_document.document.html">Pxp_document.document</a></code></pre><div class="info"> Creates a copy of the passed document by marshalling it, and restoring the document. The new document will have a copy of the original DTD, and a copy of the XML tree that will have been created according to the passed spec. The new configuration is used when building the new document, so it is possible to change the character encoding and the namespace management. <p> <b>Known problems.</b> Although it is tried to keep as much information as possible, there are unfortunately a few losses. Especially the entities are not copied. They are missing in the copied DTD object, and also the entity ID's in the nodes are only fake ID's that are not connected with real entities.<br> </div> </body></html>