<!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_ev_parser.html"> <link rel="next" href="Pxp_dtd_parser.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="Events as lists" rel="Section" href="#2_Eventsaslists"> <link title="Filters" rel="Section" href="#2_Filters"> <link title="Helpers for namespace processing" rel="Section" href="#2_Helpersfornamespaceprocessing"> <link title="Printing event streams" rel="Section" href="#2_Printingeventstreams"> <title>PXP Reference : Pxp_event</title> </head> <body> <div class="navbar"><a href="Pxp_ev_parser.html">Previous</a> <a href="index.html">Up</a> <a href="Pxp_dtd_parser.html">Next</a> </div> <center><h1>Module <a href="type_Pxp_event.html">Pxp_event</a></h1></center> <br> <pre><span class="keyword">module</span> Pxp_event: <code class="code"><span class="keyword">sig</span></code> <a href="Pxp_event.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Dealing with events (for pull parsing)<br> <hr width="100%"> <br> Dealing with events (for pull parsing)<br> <br> <a name="2_Eventsaslists"></a> <h2>Events as lists</h2><br> <pre><span class="keyword">val</span> <a name="VALto_list"></a>to_list : <code class="type">(unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> list</code></pre><div class="info"> Fetch all events from the pull function, and return the corresponding list of events.<br> </div> <pre><span class="keyword">val</span> <a name="VALof_list"></a>of_list : <code class="type"><a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> list -> unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option</code></pre><div class="info"> <code class="code">of_list l</code>: Create a pull function fetching the events from <code class="code">l</code><br> </div> <pre><span class="keyword">val</span> <a name="VALconcat"></a>concat : <code class="type">(unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) list -> unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option</code></pre><div class="info"> <code class="code"><span class="keyword">let</span> p = concat l</code>: The pull functions contained in the list <code class="code">l</code> are concatenated, and a new pull function <code class="code">p</code> is created that pulls from the functions of the list in turn (when one function indicates the end of the events, it is continued with the next function in the list).<br> </div> <pre><span class="keyword">val</span> <a name="VALiter"></a>iter : <code class="type">(<a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> -> unit) -> (unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) -> unit</code></pre><div class="info"> <code class="code">iter f p</code>: The pull function <code class="code">p</code> is repeatedly called to get a stream of events <code class="code">e</code>. For each event the function <code class="code">f</code> is called.<br> </div> <pre><span class="keyword">val</span> <a name="VALextract"></a>extract : <code class="type"><a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> -><br> (unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) -> unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option</code></pre><div class="info"> <code class="code"><span class="keyword">let</span> next' = extract e next</code>: Extracts a subexpression from the pull function <code class="code">next</code> prepended by <code class="code">e</code>. A subexpression consists of either<ul> <li>a single data, comment, PI, or error event</li> <li>a start tag, either of an element, a super root, or a document, until the corresponding end tag</li> <li>a position event followed by a subexpression</li> </ul> The returned pull function contains all events of the subexpression. When the extracted stream is read, the original stream is read, too. <p> Example: <pre></pre><code class="code"> <span class="keyword">let</span> l = [ <span class="constructor">E_pinstr</span>; <span class="constructor">E_start_tag</span>; <span class="constructor">E_data</span>; <span class="constructor">E_start_tag</span>; <span class="constructor">E_end_tag</span>;<br> <span class="constructor">E_comment</span>; <span class="constructor">E_end_tag</span>; <span class="constructor">E_data</span> ];;<br> <span class="keyword">let</span> g = of_list l;;<br> g();;<br> <span class="keyword">let</span> <span class="constructor">Some</span> e = g();; <span class="comment">(* e = E_start_tag *)</span><br> <span class="keyword">let</span> g' = extract e g;;<br> g'();; <span class="comment">(* returns Some E_start_tag *)</span><br> ...<br> g'();; <span class="comment">(* returns Some E_end_tag *)</span><br> g'();; <span class="comment">(* returns None, end of subexpression *)</span><br> g();; <span class="comment">(* returns Some E_data *)</span><br> g();; <span class="comment">(* returns None *)</span><br> </code><pre></pre><br> </div> <br> <a name="2_Filters"></a> <h2>Filters</h2><br> <pre><span class="keyword">type</span> <a name="TYPEpull_fn"></a><code class="type"></code>pull_fn = <code class="type">unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option</code> </pre> <div class="info"> The result type of <a href="Pxp_ev_parser.html#VALcreate_pull_parser"><code class="code"><span class="constructor">Pxp_ev_parser</span>.create_pull_parser</code></a><br> </div> <pre><span class="keyword">type</span> <a name="TYPEfilter"></a><code class="type"></code>filter = <code class="type"><a href="Pxp_event.html#TYPEpull_fn">pull_fn</a> -> <a href="Pxp_event.html#TYPEpull_fn">pull_fn</a></code> </pre> <div class="info"> A filter transforms a pull function into another pull function<br> </div> <pre><span class="keyword">val</span> <a name="VALnorm_cdata_filter"></a>norm_cdata_filter : <code class="type"><a href="Pxp_event.html#TYPEfilter">filter</a></code></pre><div class="info"> This filter<ul> <li>removes empty <code class="code"><span class="constructor">E_char_data</span></code> events</li> <li>concatenates adjacent <code class="code"><span class="constructor">E_char_data</span></code> events</li> </ul> but does not touch any other parts of the event stream.<br> </div> <pre><span class="keyword">val</span> <a name="VALdrop_ignorable_whitespace_filter"></a>drop_ignorable_whitespace_filter : <code class="type"><a href="Pxp_event.html#TYPEfilter">filter</a></code></pre><div class="info"> This filter <ul> <li>checks whether character data between elements in a "regexp" or "non-PCDATA mixed" content model consists only of whitespace, and</li> <li>removes these whitespace characters from the event stream.</li> </ul> If the check fails, a <code class="code"><span class="constructor">WF_Error</span></code> will be raised. <p> This filter works only if the DTD found in the event stream actually contains element declarations. This is usually enabled by including the <code class="code"><span class="keywordsign">`</span><span class="constructor">Extend_dtd_fully</span></code> or <code class="code"><span class="keywordsign">`</span><span class="constructor">Val_mode_dtd</span></code> options to the <code class="code">entry</code> passed to the <code class="code">create_pull_parser</code> call. Furthermore, there must be an <code class="code"><span class="constructor">E_start_doc</span></code> event. <p> This filter does not perform any other validation checks.<br> </div> <pre><span class="keyword">val</span> <a name="VALpfilter"></a>pfilter : <code class="type">(<a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> -> bool) -> <a href="Pxp_event.html#TYPEfilter">filter</a></code></pre><div class="info"> Filters an event stream by a predicate <p> Example: Remove comments: <pre></pre><code class="code"> pfilter (<span class="keyword">function</span> <span class="constructor">E_comment</span> _ <span class="keywordsign">-></span> <span class="keyword">false</span> <span class="keywordsign">|</span> _ <span class="keywordsign">-></span> <span class="keyword">true</span>) g </code><pre></pre><br> </div> <pre><span class="keyword">val</span> <a name="VALunwrap_document"></a>unwrap_document : <code class="type"><a href="Pxp_event.html#TYPEpull_fn">pull_fn</a> -> (unit -> string * <a href="Pxp_dtd.dtd.html">Pxp_dtd.dtd</a>) * <a href="Pxp_event.html#TYPEpull_fn">pull_fn</a></code></pre><div class="info"> This filter removes the document wrapping from the stream (see <a href="Intro_events.html#docs"><i>The wrapping for closed documents</i></a> for a definition what this is). It is called like <p> <pre></pre><code class="code"> <span class="keyword">let</span> (get_doc_details, next') = unwrap_document next<br> <span class="keyword">let</span> (version, dtd) = get_doc_details()<br> </code><pre></pre> <p> The returned <code class="code">filter</code> removes any <code class="code"><span class="constructor">E_start_doc</span></code>, <code class="code"><span class="constructor">E_end_doc</span></code>, <code class="code"><span class="constructor">E_start_super</span></code>, <code class="code"><span class="constructor">E_end_super</span></code>, and <code class="code"><span class="constructor">E_end_of_stream</span></code> events. If an <code class="code"><span class="constructor">E_error</span></code> event is encountered, the contained exception is raised. All other events of the stream remain. <p> The function <code class="code">get_doc_details</code> can be called to get details about the document definition. If an <code class="code"><span class="constructor">E_start_doc</span></code> event is found in the stream, the XML version string and the DTD object are returned. The function fails if <code class="code"><span class="constructor">E_start_doc</span></code> is not the first event of the stream.<br> </div> <br> <a name="2_Helpersfornamespaceprocessing"></a> <h2>Helpers for namespace processing</h2><br> <br> The names in <code class="code"><span class="constructor">E_start_tag</span></code> can be analyzed with the following.<br> <pre><span class="keyword">val</span> <a name="VALnamespace_split"></a>namespace_split : <code class="type">string -> string * string</code></pre><div class="info"> <code class="code"><span class="keyword">let</span> (p,l) = namespace_split name</code>: Splits <code class="code">name</code> into the prefix <code class="code">p</code> and the local name <code class="code">l</code>. If there is no colon in <code class="code">name</code>, the function returns <code class="code">p=<span class="string">""</span></code>, and <code class="code">l=name</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALextract_prefix"></a>extract_prefix : <code class="type">string -> string</code></pre><div class="info"> Returns the prefix in the name, or <code class="code"><span class="string">""</span></code> if there is no prefix. Same as <code class="code">fst(namespace_split name)</code>.<br> </div> <br> <a name="2_Printingeventstreams"></a> <h2>Printing event streams</h2><br> <pre><span class="keyword">type</span> <a name="TYPEdtd_style"></a><code class="type"></code>dtd_style = <code class="type">[ `Ignore | `Include | `Reference ]</code> </pre> <pre><span class="keyword">val</span> <a name="VALwrite_events"></a>write_events : <code class="type">?default:string -><br> ?dtd_style:<a href="Pxp_event.html#TYPEdtd_style">dtd_style</a> -><br> ?minimization:[ `AllEmpty | `None ] -><br> <a href="Pxp_types.html#TYPEoutput_stream">Pxp_types.output_stream</a> -><br> <a href="Pxp_types.html#TYPEencoding">Pxp_types.encoding</a> -><br> <a href="Pxp_types.html#TYPErep_encoding">Pxp_types.rep_encoding</a> -> (unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) -> unit</code></pre><div class="info"> Writes the events to the <code class="code">output_stream</code>. The events must be encoded as indicated by the <code class="code">rep_encoding</code> argument, but the output is written as specified by the <code class="code">encoding</code> argument. <p> The normalized namespace prefixes are declared as needed. Additionally, one can set the default namespace by passing <code class="code">default</code>, which must be the normalized prefix of the default namespace. <p> For <code class="code"><span class="constructor">E_doc_start</span></code> events, the DTD may be written. This is controlled by <code class="code">dtd_style</code>:<ul> <li><code class="code"><span class="keywordsign">`</span><span class="constructor">Ignore</span></code>: No <code class="code"><span class="constructor">DOCTYPE</span></code> clause is written</li> <li><code class="code"><span class="keywordsign">`</span><span class="constructor">Include</span></code>: The <code class="code"><span class="constructor">DOCTYPE</span></code> clause is written, and the DTD is included in the internal subset (the default)</li> <li><code class="code"><span class="keywordsign">`</span><span class="constructor">Reference</span></code>: The <code class="code"><span class="constructor">DOCTYPE</span></code> clause is written as a reference to an external DTD</li> </ul> Option <code class="code">minimization</code>: How to write out empty elements. <code class="code"><span class="keywordsign">`</span><span class="constructor">AllEmpty</span></code> means that all empty elements are minimized (using the <code class="code"><name/></code> form). <code class="code"><span class="keywordsign">`</span><span class="constructor">None</span></code> does not minimize at all and is the default.<br> </div> <pre><span class="keyword">val</span> <a name="VALdisplay_events"></a>display_events : <code class="type">?dtd_style:<a href="Pxp_event.html#TYPEdtd_style">dtd_style</a> -><br> ?minimization:[ `AllEmpty | `None ] -><br> <a href="Pxp_types.html#TYPEoutput_stream">Pxp_types.output_stream</a> -><br> <a href="Pxp_types.html#TYPEencoding">Pxp_types.encoding</a> -><br> <a href="Pxp_types.html#TYPErep_encoding">Pxp_types.rep_encoding</a> -> (unit -> <a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> option) -> unit</code></pre><div class="info"> Writes the events to the <code class="code">output_stream</code>. The events must be encoded as indicated by the <code class="code">rep_encoding</code> argument, but the output is written as specified by the <code class="code">encoding</code> argument. <p> Namespace prefixes are declared as defined in the namespace scopes. Missing prefixes are invented on the fly. <p> The way the DTD is printed can be set as in <code class="code">write_events</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALstring_of_event"></a>string_of_event : <code class="type"><a href="Pxp_types.html#TYPEevent">Pxp_types.event</a> -> string</code></pre><div class="info"> Returns a string representation of events, for debugging<br> </div> </body></html>