Detailed description and usage:
Using the class:
Initialization:
include_once("class_schematron.php");
$s = new Schematron();
Compiling a Schematron script (optional):
$s->compile_schematron_from_file("validation_sample1.xml");
// You can get the compiled schematron as a string
$compiled=$s->get_compiled("validation_sample1.xml");
// Or you can save it as a file
$s->save_compiled("validation_sample1.xml","validation1.xsl");
Running an uncompiled schematron script from a file to validate an XML file:
$ret=$s->schematron_validate_file_using_file("sample1.xml","validation_sample1.xml");
Running an uncompiled schematron script from mem to validate an XML file:
$ret=$s->schematron_validate_file_using_mem("sample1.xml",$schematron);
Running an uncompiled schematron from a file to validate an XML document in memory:
$ret=$s->schematron_validate_mem_using_file($xml,"validation_file.xml");
Running an uncompiled schematron from mem to validate an XML document in memory:
$ret=$s->schematron_validate_mem_using_mem($xml,$schematron);
Running an compiled schematron script from a file to validate an XML file:
$ret=$s->schematron_validate_file_using_compiled_file("sample1.xml","validation_sample1.xml");
Running an compiled schematron script from mem to validate an XML file:
$ret=$s->schematron_validate_file_using_compiled_mem("sample1.xml",$schematron);
Running an compiled schematron from a file to validate an XML document in memory:
$ret=$s->schematron_validate_mem_using_compiled_file($xml,"validation_file.xml");
Running an compiled schematron from mem to validate an XML document in memory:
$ret=$s->schematron_validate_mem_using_compiled_mem($xml,$schematron);
Documentation
Classes
class_schematron
Extends: None
Description: This class implements the Schematron 1.5 language allowing to validate XML files from PHP using Schematron.
Method Summary |
void |
Schematron()
Constructor |
string |
compile_schematron_from_file(string $filename)
Compiles a schematron file to XSLT |
string |
compile_schematron_from_mem(string $xml)
Compiles a Schematron script from a PHP string to an XSLT stylesheet |
string |
get_compiled(string $xml_filename)
Returns the compiled XSLT stylesheet for a Schematron script |
boolean |
save_compiled(string $xml_filename, string $filename)
Saves a previously compiled Schematron script to a file |
string |
validate_mem_using_mem(string $xml_string, string $validation_string)
Validates an XML string using a Schematron script from a string. |
string |
validate_mem_using_file(string $xml_string, string $validation_filename)
Validates an XML document in a string using a Schematron script from a file |
string |
validate_file_using_mem(string $xml_filename, string $validation_string)
Validates an XML document in a file using a Schematron script from a PHP string |
string |
validate_file_using_file(string $xml_filename, string $validation_filename)
Validates an XML document in a file using a Schematron script from a file |
string |
validate_mem_using_compiled_mem(string $xml_string, string $validation_string)
Validates an XML document held in a PHP string using a compiled Schematron scrip |
string |
validate_mem_using_compiled_file(string $xml_string, string $validation_filename)
Validates an XML document held in memory using a compiled Schematron script from |
string |
validate_file_using_compiled_mem(string $xml_filename, string $validation_string)
Validates an XML documen in a file using a compiled Schematron script from a PHP |
string |
validate_file_using_compiled_file(string $xml_filename, string $validation_filename)
Validates an XML document in a file using a compiled Schematron script in a file |
Schematron
void Schematron(string $xml_filename, string $validation_filename)
- This is the class constructor
-
- Parameters:
-
- Returns:
- Nothing
- Throws:
None
compile_schematron_from_file
string compile_schematron_from_file(string $filename)
- Compiles a schematron 1.5 script generating an XSLT stylesheet.
-
- Parameters:
-
$filename - Name of the file containing the Schematron script.
- Returns:
- The compiled Schematron script as an XSLT stylesheet
- Throws:
XSLT errors if it cannot compile the Schematron file.
compile_schematron_from_mem
string compile_schematron_from_mem(string $xml)
- This compiles a schematron 1.5 script held in memory in a PHP string returning an XSLT stylesheet that can be used to validate XML documents following the rules defined in the script.
-
- Parameters:
-
$xml - String containing the Schematron 1.5 script
- Returns:
- The XSLT stylesheet corresponding to the validation. (The compiled schematron script)
- Throws:
Can raise an error if the Schematron cannot be compiled (XSLT errors)
get_compiled
string get_compiled(string $xml_filename)
- When a schematron script is used or compiled from a file the schematron class stores a compiled representation of the script as an XSLT stylesheet, you can obtain this stylesheet and use it in methods receiving a compiled Schematron script.
-
- Parameters:
-
$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.
- Returns:
- 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).
- Throws:
None
save_compiled
boolean save_compiled(string $xml_filename, string $filename)
- This method is used to save a previously compiled or used Schematron script as an XSLT stylesheet to a file.
-
- Parameters:
-
$xml_filename - This is the name that was used in a compilation or validation method using a Schematron script from a filename, one used or compiled the class stores a compiled representation as an XSLT stylesheet that can now be saved to a file to be used later as a compiled Schematron script.
$filename - This is the name of the file where the method will write the compiled (XSLT) schematron script.
- Returns:
- true if the compiled scripts exists in the class or false if not.
- Throws:
Can throw an error if the file cannot be saved to disk.
validate_mem_using_mem
string validate_mem_using_mem(string $xml_string, string $validation_string)
- Validates an XML string using a Schematron script from a string.
-
- Parameters:
-
$xml_string - string containing the XML document to be validated
$validation_string - String containing the Schematron script to be used
- Returns:
- The result of the validation.
- Throws:
An XSLT error if the schematron script is invalid
validate_mem_using_file
string validate_mem_using_file(string $xml_string, string $validation_filename)
- 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.
-
- Parameters:
-
$xml_string - String containing the XML document to be validated
$validation_filename - Filename of the Schematron script to be used
- Returns:
- The result of the validation
- Throws:
Can throw an XSLT error if the Schematron script is invalid.
validate_file_using_mem
string validate_file_using_mem(string $xml_filename, string $validation_string)
- Validates an XML document in a file using a Schematron script from a PHP string
-
- Parameters:
-
$xml_filename - Name of the file contaning the XML document to be validated
$validation_string - A PHP string containing the Schematron script to be used
- Returns:
- The result of the validation
- Throws:
Can throw an error (XSLT) if the Schematron script is invalid.
validate_file_using_file
string validate_file_using_file(string $xml_filename, string $validation_filename)
- Validates an XML document in a file using a Schematron script from a file
-
- Parameters:
-
$xml_filename - Name of the file containing the XML document to be validated
$validation_filename - Name of the filename containing the Schematron script to be used
- Returns:
- The result of the validation
- Throws:
Can throw an XSLT error if the Schematron script is invalid
validate_mem_using_compiled_mem
string validate_mem_using_compiled_mem(string $xml_string, string $validation_string)
- Validates an XML document held in a PHP string using a compiled Schematron script contained in a PHP string as an XSLT stylesheet.
-
- Parameters:
-
$xml_string - A PHP string containing the XML document to be validated
$validation_string - A PHP string containing a compiled Schematron script (as XSLT)
- Returns:
- The result of the validation.
- Throws:
Can throw an XSLT error
validate_mem_using_compiled_file
string validate_mem_using_compiled_file(string $xml_string, string $validation_filename)
- 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.
-
- Parameters:
-
$xml_string - A PHP string containing the XML document to be validated
$validation_filename - Name of the file containing the compiled version of the Schematron script
- Returns:
- The result of the validation.
- Throws:
Can throw an XSLT error if the compiled script has errors
validate_file_using_compiled_mem
string validate_file_using_compiled_mem(string $xml_filename, string $validation_string)
- Validates an XML documen in a file using a compiled Schematron script from a PHP string
-
- Parameters:
-
$xml_filename - Name of the file containing the XML document to be validated
$validation_string - PHP String containing the compiled version of a Schematron script
- Returns:
- The result of the validation
- Throws:
Can throw an XSLT error if the compiled Schematron script has errors
validate_file_using_compiled_file
string validate_file_using_compiled_file(string $xml_filename, string $validation_filename)
- Validates an XML document in a file using a compiled Schematron script in a file
-
- Parameters:
-
$xml_filename - Name of the file containing the XML document to be validated
$validation_filename - Name of the file containing the compiled representation of the Schematron script to be used
- Returns:
- The result of the validation
- Throws:
Can throw an XSLT error if the compiled script has errors
|