topical media & game development
server-php-xml-class-schematron-class-schematron.htm / htm
<html>
<head>
<title>Schematron (class_schematron.php)</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div align="center">
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#aaaaee" class="text" align="center"><a href="http://phpxmlclasses.sourceforge.net/">PHP XML Classes</a></td>
</tr>
</table>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#aaaaee" class="textblbl" align="center">Schematron (class_schematron.php)</td>
</tr>
</table>
<br/>
<table border="0" width="80%">
<tr>
<td bgcolor="#eeeeff" class="text">Description: This class implements the <a href="http://www.ascc.net/xml/resource/schematron/schematron.html">Schematron 1.5</a>
language for XML validation. Schematron scripts can be used directly from XML or pre-compiled into an XSLT stylesheet for later usage. XML files
to be validated can be read from disk files or php strings.
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<td valign="top" class="text" width="50%"><b>NEWS:</b>
<ul>
<li> 05-15-02 First version of this class released.
</ul>
</td>
<td valign="top" width="50%" class="text">
This class code as well as the documentation are hosted at <a href="http://www.sourceforge.net">SourceForge</a>
please visit our <a href="http://phpxmlclasses.sourceforge.net/">SourceForge page</a> for releases, documentation, bug-tracking, support
forums and mailing lists.
</td>
</tr>
</table>
<br/>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td class="textbl" bgcolor="aaaaee" width="50%">Resources</td>
<td class="textbl" bgcolor="aaaaee" width="50%">Requirements</td>
</tr>
</table>
<table border="1" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li><a class="textbl" href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads</a>
<li><a class="textbl" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxmlclasses/schematron/">Browse CVS</a>
<li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a>
</ul>
</td>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li>PHP 4.0.5+
<li>XSLT extension (Sablotron)
</ul>
</td>
</tr>
</table>
<br/>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td class="textbl" bgcolor="aaaaee" width="50%">Features</td>
<td class="textbl" bgcolor="aaaaee" width="50%">To-dos</td>
</tr>
</table>
<table border="1" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li> XML files to be validated can be read from PHP strings or files
<li> Schematron scripts can be read from files or PHP strings
<li> Schematron scripts can be used compiled or uncompiled
<li> The class caches schematron compilations in order to prevent a schematron script
from being compiled twice.
<li> The Schematron 1.5 XSLT implementation is "inlined" in the class, no aditional
files are needed.
</ul>
</td>
<td valign="top" bgcolor="ddddff" class="text" width="50%">
<ul>
<li>
</ul>
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<!--
<td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
<ul>
<li>Class
<li>Class
<li>Class
</ul>
</td> -->
<td valign="top" width="100%" class="text">
Contact:
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<!--
<td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
<ul>
<li>Class
<li>Class
<li>Class
</ul>
</td> -->
<td valign="top" width="100%" class="text">
Detailed description and usage:<br/>
<b>Using the class:</b><br/><br/>
<b>Initialization:</b><br/>
<pre>include_once("class_schematron.php");
s->compile_schematron_from_file("validation_sample1.xml");
// You can get the compiled schematron as a string
s->get_compiled("validation_sample1.xml");
// Or you can save it as a file
ret=ret=schematron);</pre><br/>
<b>Running an uncompiled schematron from a file to validate an XML document in memory:</b><br/>
<pre>s->schematron_validate_mem_using_file(ret=xml,ret=ret=schematron);</pre><br/>
<b>Running an compiled schematron from a file to validate an XML document in memory:</b><br/>
<pre>s->schematron_validate_mem_using_compiled_file(ret=xml,filename)</CODE>
<BR>
Compiles a schematron file to XSLT</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method3">compile_schematron_from_mem</A></B>(string xml_filename)</CODE>
<BR>
Returns the compiled XSLT stylesheet for a Schematron script</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method5">save_compiled</A></B>(string filename)</CODE>
<BR>
Saves a previously compiled Schematron script to a file</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method6">validate_mem_using_mem</A></B>(string validation_string)</CODE>
<BR>
Validates an XML string using a Schematron script from a string.</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method7">validate_mem_using_file</A></B>(string validation_filename)</CODE>
<BR>
Validates an XML document in a string using a Schematron script from a file</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method8">validate_file_using_mem</A></B>(string validation_string)</CODE>
<BR>
Validates an XML document in a file using a Schematron script from a PHP string</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method9">validate_file_using_file</A></B>(string validation_filename)</CODE>
<BR>
Validates an XML document in a file using a Schematron script from a file</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method10">validate_mem_using_compiled_mem</A></B>(string validation_string)</CODE>
<BR>
Validates an XML document held in a PHP string using a compiled Schematron scrip</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method11">validate_mem_using_compiled_file</A></B>(string validation_filename)</CODE>
<BR>
Validates an XML document held in memory using a compiled Schematron script from</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method12">validate_file_using_compiled_mem</A></B>(string validation_string)</CODE>
<BR>
Validates an XML documen in a file using a compiled Schematron script from a PHP</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> string</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class21method13">validate_file_using_compiled_file</A></B>(string validation_filename)</CODE>
<BR>
Validates an XML document in a file using a compiled Schematron script in a file</TD>
</TR>
<!-- A ROW -->
</TABLE>
<P>
<!-- METHOD SUMMARY -->
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>
<!-- method -->
<A NAME="class21method1"><!-- --></A>
<H3>Schematron</H3>
<PRE>
void <B>Schematron</B>(string validation_filename)</PRE>
<DL>
<DD>This is the class constructor
<DL>
<DT><B>Parameters:</B><DD>
<DT><B>Returns:</B><DD>Nothing<DT><B>Throws:</B><DD><CODE>None</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method2"><!-- --></A>
<H3>compile_schematron_from_file</H3>
<PRE>
string <B>compile_schematron_from_file</B>(string filename - Name of the file containing the Schematron script.<br><DT><B>Returns:</B><DD>The compiled Schematron script as an XSLT stylesheet<DT><B>Throws:</B><DD><CODE>XSLT errors if it cannot compile the Schematron file.</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method3"><!-- --></A>
<H3>compile_schematron_from_mem</H3>
<PRE>
string <B>compile_schematron_from_mem</B>(string xml - String containing the Schematron 1.5 script<br><DT><B>Returns:</B><DD>The XSLT stylesheet corresponding to the validation. (The compiled schematron script)<DT><B>Throws:</B><DD><CODE>Can raise an error if the Schematron cannot be compiled (XSLT errors)</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method4"><!-- --></A>
<H3>get_compiled</H3>
<PRE>
string <B>get_compiled</B>(string xml_filename - This is the name of the file that originally held the Schematron script, note that the file doesn't need to exist now. The name should match the name used in previously invoked validation method or compilation method.<br><DT><B>Returns:</B><DD>False if the script was never used or compiled.
or
The Schematron compiled XSLT stylesheet corresponding to the filename provided as a parameter (the name of the file that originally held the Schematron script). <DT><B>Throws:</B><DD><CODE>None</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method5"><!-- --></A>
<H3>save_compiled</H3>
<PRE>
boolean <B>save_compiled</B>(string filename)</PRE>
<DL>
<DD>This method is used to save a previously compiled or used Schematron script as an XSLT stylesheet to a file.<DD>
<DL>
<DT><B>Parameters:</B><DD>
filename - This is the name of the file where the method will write the compiled (XSLT) schematron script.<br><DT><B>Returns:</B><DD>true if the compiled scripts exists in the class or false if not.<DT><B>Throws:</B><DD><CODE>Can throw an error if the file cannot be saved to disk.</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method6"><!-- --></A>
<H3>validate_mem_using_mem</H3>
<PRE>
string <B>validate_mem_using_mem</B>(string validation_string)</PRE>
<DL>
<DD>Validates an XML string using a Schematron script from a string.<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_string - String containing the Schematron script to be used<br><DT><B>Returns:</B><DD>The result of the validation.<DT><B>Throws:</B><DD><CODE>An XSLT error if the schematron script is invalid</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method7"><!-- --></A>
<H3>validate_mem_using_file</H3>
<PRE>
string <B>validate_mem_using_file</B>(string validation_filename)</PRE>
<DL>
<DD>Validates an XML document in a string using a Schematron script from a file. The compiled Schematron script will be cached and can be saved. <DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_filename - Filename of the Schematron script to be used<br><DT><B>Returns:</B><DD>The result of the validation<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error if the Schematron script is invalid.</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method8"><!-- --></A>
<H3>validate_file_using_mem</H3>
<PRE>
string <B>validate_file_using_mem</B>(string validation_string)</PRE>
<DL>
<DD>Validates an XML document in a file using a Schematron script from a PHP string<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_string - A PHP string containing the Schematron script to be used<br><DT><B>Returns:</B><DD>The result of the validation<DT><B>Throws:</B><DD><CODE>Can throw an error (XSLT) if the Schematron script is invalid.</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method9"><!-- --></A>
<H3>validate_file_using_file</H3>
<PRE>
string <B>validate_file_using_file</B>(string validation_filename)</PRE>
<DL>
<DD>Validates an XML document in a file using a Schematron script from a file<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_filename - Name of the filename containing the Schematron script to be used<br><DT><B>Returns:</B><DD>The result of the validation<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error if the Schematron script is invalid</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method10"><!-- --></A>
<H3>validate_mem_using_compiled_mem</H3>
<PRE>
string <B>validate_mem_using_compiled_mem</B>(string validation_string)</PRE>
<DL>
<DD>Validates an XML document held in a PHP string using a compiled Schematron script contained in a PHP string as an XSLT stylesheet.<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_string - A PHP string containing a compiled Schematron script (as XSLT)<br><DT><B>Returns:</B><DD>The result of the validation.<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method11"><!-- --></A>
<H3>validate_mem_using_compiled_file</H3>
<PRE>
string <B>validate_mem_using_compiled_file</B>(string validation_filename)</PRE>
<DL>
<DD>Validates an XML document held in memory using a compiled Schematron script from a file. The compiled script should be an XSLT stylesheet representing the Schematron transformation to be done.<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_filename - Name of the file containing the compiled version of the Schematron script<br><DT><B>Returns:</B><DD>The result of the validation.<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error if the compiled script has errors</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method12"><!-- --></A>
<H3>validate_file_using_compiled_mem</H3>
<PRE>
string <B>validate_file_using_compiled_mem</B>(string validation_string)</PRE>
<DL>
<DD>Validates an XML documen in a file using a compiled Schematron script from a PHP string<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_string - PHP String containing the compiled version of a Schematron script<br><DT><B>Returns:</B><DD>The result of the validation<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error if the compiled Schematron script has errors</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- method -->
<A NAME="class21method13"><!-- --></A>
<H3>validate_file_using_compiled_file</H3>
<PRE>
string <B>validate_file_using_compiled_file</B>(string validation_filename)</PRE>
<DL>
<DD>Validates an XML document in a file using a compiled Schematron script in a file<DD>
<DL>
<DT><B>Parameters:</B><DD>
validation_filename - Name of the file containing the compiled representation of the Schematron script to be used<br><DT><B>Returns:</B><DD>The result of the validation<DT><B>Throws:</B><DD><CODE>Can throw an XSLT error if the compiled script has errors</CODE>
</DL>
</DD>
</DL>
<HR>
<!-- a method -->
<!-- ============ METHOD DETAIL ========== -->
</td>
</tr>
</table>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.