Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > d9c1887ff364dc87e282490223567c41 > files > 121

ocaml-pxp-1.2.1-1mdv2010.0.i586.rpm

<!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="Intro_getting_started.html">
<link rel="next" href="Intro_preprocessor.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="Advanced topics" rel="Section" href="#1_Advancedtopics">
<link title="How validation and well-formedness modes are implemented" rel="Subsection" href="#valmode">
<link title="The mixed mode" rel="Subsection" href="#mixedmode">
<link title="Irregular nodes: namespace nodes and attribute nodes" rel="Subsection" href="#irrnodes">
<title>PXP Reference : Intro_advanced</title>
</head>
<body>
<div class="navbar"><a href="Intro_getting_started.html">Previous</a>
&nbsp;<a href="index.html">Up</a>
&nbsp;<a href="Intro_preprocessor.html">Next</a>
</div>
<center><h1>Intro_advanced</h1></center>
<br>
<br>
<a name="1_Advancedtopics"></a>
<h1>Advanced topics</h1>
<p>

<a name="valmode"></a>
<h2>How validation and well-formedness modes are implemented</h2>
<p>

Validation mainly means to check whether the XML tree fulfills a
condition, but this is not all. Validation also performs some normalizations,
e.g.:<ul>
<li>Whitespace characters may be removed from the tree where the DTD allows it</li>
<li>Default values of attributes are added when the XML text omits them</li>
</ul>

If there were no modifications of the XML tree, validation could be
completely implemented as a property of the DTD object, which is the
logical instance for checking such a constraint. However, this is not
true, so many checks and normalizations have been implemented within
the document tree, and are triggered there. Nevertheless, these checks
and normalizations are finally controlled by the DTD, which remains
the final controlling instance. This means that validation can be
turned off by setting a flag in the DTD object.
<p>

An example: If the DTD does not find the declaration of an element,
attribute, or notation, it is free to react in two ways. It could
immediately signal a validation error.  It can also indicate that the
requested object is not found, but that the caller should accept
that. The caller is here the document tree which tries to trigger this
validation check by going to the DTD.  If the result of this check is
"accept", the tree simply skips all further validation checks. This is
how well-formedness mode is implemented.
<p>

Now the validation case: If the declaration is found, the document
tree takes it, and calls the corresponding validation check routine
(often implemented as private methods of the tree nodes). The
declaration is often not passed back from the DTD to the node tree in
the form as originally parsed, but preprocessed, so that the
validation check can run quicker. For elements, the preprocessed
declaration is the <code class="code">validation_record</code>, defined in <code class="code">pxp_dtd.ml</code>.
<p>

When default values of attributes have to be complemented, the
<code class="code">validation_record</code> contains a preprocessed list of attributes.
Actually, the node tree takes this list, and looks whether the XML
text overrides any of these, and makes the resulting list to the
official attribute list of the element node. This kind of dealing
with default values is optimized for the case that the are many
default values, and overriding occurs only seldom.
<p>

The basic well-formedness checks (like proper nesting of tags) are
already implemented in the recursive-descent parser module. Neither
the document tree nor the DTD has to check any of these.
<p>

<a name="mixedmode"></a>
<h2>The mixed mode</h2>
<p>

Because well-formedness mode is achieved by turning off certain
validation checks, it is also possible to run PXP in a mixed mode
between both standard modes. Especially, it is possible to check
existing declarations, but also to accept missing declarations.
<p>

There are two special processing instructions one can include into
the DTD part of a document:
<p>
<ul>
<li><code class="code">&lt;?pxp:dtd optional-element-<span class="keyword">and</span>-notation-declarations<span class="keywordsign">?&gt;</span></code>: This
  instruction allows to use elements and notation in the XML text
  without declaration. These elements and notations are then handled
  as in well-formedness mode. Existing declarations have to be obeyed,
  however.</li>
<li><code class="code">&lt;?pxp:dtd optional-attribute-declarations elements=<span class="string">"e1 e2 ..."</span><span class="keywordsign">?&gt;</span></code>
  This instruction allows to use attributes of the mentioned elements
  <code class="code">e1</code>, <code class="code">e2</code>, etc. without declaration. These attributes are then
  handled as in well-formedness mode. Existing declarations have to be obeyed,
  however. Also, attributes of elements not mentioned still need to be
  declared.</li>
</ul>

Programmatically, the same effects can also be achieved by setting
the <code class="code">allow_arbitrary</code> flags of declaration objects.
<p>

<a name="irrnodes"></a>
<h2>Irregular nodes: namespace nodes and attribute nodes</h2>
<p>

These node types primarily exist because XML standards require them.
For example, in <code class="code"><span class="constructor">XPath</span></code> it is possible to include attributes into
sets of nodes. Of course, this requires that attributes have the same
type as other nodes. In order to support these standards better, the
node types <code class="code"><span class="constructor">T_attribute</span></code> and <code class="code"><span class="constructor">T_namespace</span></code> have been added to the
tree definition.
<p>

Note that these node types are meant "read-only": They provide an
alternate view of the properties of the node tree. It does not make
sense to modify these nodes, because they are only derived from some
original values that would remain unmodified.
<p>

In order to get the attribute nodes, just call <code class="code">attributes_as_node</code>
(link: <a href="Pxp_document.node.html#METHODattributes_as_nodes"><code class="code"><span class="constructor">Pxp_document</span>.node.attributes_as_nodes</code></a>). This method takes a
snapshot of the current attribute list, turns it into the form of a
node list, and returns it. Note that when the original attribute
list is modified, the attribute nodes are not notified by this, and
remain unchanged.
<p>

See <a href="Pxp_document.node.html#METHODattributes_as_nodes"><code class="code"><span class="constructor">Pxp_document</span>.node.attributes_as_nodes</code></a> for details how the
attribute nodes work (e.g. how their value can be retrieved).
<p>

Attribute nodes are irregular nodes. They are only returned by this
special method, but do not appear in the regular list of children of
the element. Note that this corresponds to how XML standards like
<code class="code"><span class="constructor">XPath</span></code> define attribute nodes.
<p>

Namespace nodes are very similar to attribute nodes. They 
provide an alternate view of the <code class="code">namespace_scope</code> objects, and there
is the method <code class="code">namespaces_as_nodes</code> (link: 
<a href="Pxp_document.node.html#METHODnamespaces_as_nodes"><code class="code"><span class="constructor">Pxp_document</span>.node.namespaces_as_nodes</code></a>) that returns these nodes.
As attribute nodes, namespace nodes are irregular, and once created,
they are not automatically updated when the orginal namespace scope
objects are changed.
<p>

<a name="3_Linkstootherdocumentation"></a>
<h3>Links to other documentation</h3>
<p>
<ul>
<li><a href="Pxp_document.node.html#METHODattributes_as_nodes"><code class="code"><span class="constructor">Pxp_document</span>.node.attributes_as_nodes</code></a></li>
<li><a href="Pxp_document.node.html#METHODnamespaces_as_nodes"><code class="code"><span class="constructor">Pxp_document</span>.node.namespaces_as_nodes</code></a></li>
<li><a href="Pxp_document.attribute_impl.html"><code class="code"><span class="constructor">Pxp_document</span>.attribute_impl</code></a></li>
<li><a href="Pxp_document.namespace_attribute_impl.html"><code class="code"><span class="constructor">Pxp_document</span>.namespace_attribute_impl</code></a></li>
<li><a href="Pxp_document.namespace_impl.html"><code class="code"><span class="constructor">Pxp_document</span>.namespace_impl</code></a></li>
<li><a href="Pxp_document.html#VALattribute_name"><code class="code"><span class="constructor">Pxp_document</span>.attribute_name</code></a></li>
<li><a href="Pxp_document.html#VALattribute_value"><code class="code"><span class="constructor">Pxp_document</span>.attribute_value</code></a></li>
<li><a href="Pxp_document.html#VALattribute_string_value"><code class="code"><span class="constructor">Pxp_document</span>.attribute_string_value</code></a></li>
<li><a href="Pxp_document.html#VALnamespace_normprefix"><code class="code"><span class="constructor">Pxp_document</span>.namespace_normprefix</code></a></li>
<li><a href="Pxp_document.html#VALnamespace_display_prefix"><code class="code"><span class="constructor">Pxp_document</span>.namespace_display_prefix</code></a></li>
<li><a href="Pxp_document.html#VALnamespace_uri"><code class="code"><span class="constructor">Pxp_document</span>.namespace_uri</code></a></li>
<li><a href="Pxp_document.html#docorder"><i>Document order</i></a></li>
</ul>

<br>
</body></html>